[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" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 65 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 66 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 67 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 68 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 69 | #include "net/http/http_stream_factory.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 70 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 71 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 72 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 73 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 74 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 75 | #include "net/log/test_net_log_entry.h" |
| 76 | #include "net/log/test_net_log_util.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 77 | #include "net/proxy_resolution/mock_proxy_resolver.h" |
| 78 | #include "net/proxy_resolution/proxy_config_service_fixed.h" |
| 79 | #include "net/proxy_resolution/proxy_info.h" |
Lily Houghton | ffe89daa0 | 2018-03-09 18:30:03 | [diff] [blame] | 80 | #include "net/proxy_resolution/proxy_resolution_service.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 81 | #include "net/proxy_resolution/proxy_resolver.h" |
| 82 | #include "net/proxy_resolution/proxy_resolver_factory.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 83 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 84 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 85 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 86 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 87 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 88 | #include "net/socket/next_proto.h" |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 89 | #include "net/socket/socket_tag.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 90 | #include "net/socket/socket_test_util.h" |
Matt Menke | 4b412da | 2019-01-25 19:31:12 | [diff] [blame] | 91 | #include "net/socket/socks_connect_job.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 92 | #include "net/socket/ssl_client_socket.h" |
Bence Béky | 94658bf | 2018-05-11 19:22:58 | [diff] [blame] | 93 | #include "net/spdy/spdy_session.h" |
| 94 | #include "net/spdy/spdy_session_pool.h" |
| 95 | #include "net/spdy/spdy_test_util_common.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 96 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 97 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 98 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 99 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 100 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 101 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 102 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 103 | #include "net/test/test_data_directory.h" |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 104 | #include "net/test/test_with_scoped_task_environment.h" |
Victor Vasiliev | 27cc771 | 2019-01-24 11:50:14 | [diff] [blame] | 105 | #include "net/third_party/quiche/src/spdy/core/spdy_framer.h" |
[email protected] | baee31a | 2018-01-18 06:10:23 | [diff] [blame] | 106 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 107 | #include "net/url_request/static_http_user_agent_settings.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 108 | #include "net/websockets/websocket_handshake_stream_base.h" |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 109 | #include "net/websockets/websocket_test_util.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 110 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 111 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 112 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 113 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 114 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 115 | #if defined(NTLM_PORTABLE) |
| 116 | #include "base/base64.h" |
| 117 | #include "net/ntlm/ntlm_test_data.h" |
| 118 | #endif |
| 119 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 120 | #if BUILDFLAG(ENABLE_REPORTING) |
| 121 | #include "net/network_error_logging/network_error_logging_service.h" |
| 122 | #include "net/network_error_logging/network_error_logging_test_util.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 123 | #include "net/reporting/reporting_cache.h" |
| 124 | #include "net/reporting/reporting_client.h" |
| 125 | #include "net/reporting/reporting_header_parser.h" |
| 126 | #include "net/reporting/reporting_service.h" |
| 127 | #include "net/reporting/reporting_test_util.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 128 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 129 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 130 | using net::test::IsError; |
| 131 | using net::test::IsOk; |
| 132 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 133 | using base::ASCIIToUTF16; |
| 134 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 135 | //----------------------------------------------------------------------------- |
| 136 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 137 | namespace net { |
| 138 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 139 | namespace { |
| 140 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 141 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 142 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 143 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 144 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 145 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 146 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 147 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 148 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 149 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 150 | const base::string16 kSecond(ASCIIToUTF16("second")); |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 151 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 152 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 153 | const char kAlternativeServiceHttpHeader[] = |
| 154 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 155 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 156 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 157 | return session |
| 158 | ->GetSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 159 | ProxyServer::Direct()) |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 160 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 161 | } |
| 162 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 163 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 164 | return session |
| 165 | ->GetSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 166 | ProxyServer::Direct()) |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 167 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 168 | } |
| 169 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 170 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 171 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 172 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 173 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 174 | if (!params) |
| 175 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 176 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 177 | if (!params->GetList("headers", &header_list)) |
| 178 | return false; |
| 179 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 180 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 181 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 182 | return true; |
| 183 | } |
| 184 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 185 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 186 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 187 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 188 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 189 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 190 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 191 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 192 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 193 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 194 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 195 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 196 | |
| 197 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 198 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 199 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 200 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 201 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 202 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 203 | } |
| 204 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 205 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 206 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 207 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 208 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 209 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 210 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 211 | |
| 212 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 213 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 214 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 215 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 216 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 217 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 218 | load_timing_info.send_start); |
| 219 | |
| 220 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 221 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 222 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 223 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 224 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 225 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 229 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 230 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 231 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 232 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 233 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 234 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 235 | |
| 236 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 237 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 238 | load_timing_info.proxy_resolve_end); |
| 239 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 240 | load_timing_info.send_start); |
| 241 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 242 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 243 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 244 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 245 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 246 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 250 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 251 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 252 | int connect_timing_flags) { |
| 253 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 254 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 255 | |
| 256 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 257 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 258 | load_timing_info.proxy_resolve_end); |
| 259 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 260 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 261 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 262 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 263 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 264 | load_timing_info.send_start); |
| 265 | |
| 266 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 267 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 268 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 269 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 270 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 271 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 272 | } |
| 273 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 274 | // ProxyResolver that records URLs passed to it, and that can be told what |
| 275 | // result to return. |
| 276 | class CapturingProxyResolver : public ProxyResolver { |
| 277 | public: |
| 278 | CapturingProxyResolver() |
| 279 | : proxy_server_(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 80)) {} |
| 280 | ~CapturingProxyResolver() override = default; |
| 281 | |
| 282 | int GetProxyForURL(const GURL& url, |
| 283 | ProxyInfo* results, |
| 284 | CompletionOnceCallback callback, |
| 285 | std::unique_ptr<Request>* request, |
| 286 | const NetLogWithSource& net_log) override { |
| 287 | results->UseProxyServer(proxy_server_); |
| 288 | resolved_.push_back(url); |
| 289 | return OK; |
| 290 | } |
| 291 | |
| 292 | // Sets whether the resolver should use direct connections, instead of a |
| 293 | // proxy. |
| 294 | void set_proxy_server(ProxyServer proxy_server) { |
| 295 | proxy_server_ = proxy_server; |
| 296 | } |
| 297 | |
| 298 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 299 | |
| 300 | private: |
| 301 | std::vector<GURL> resolved_; |
| 302 | |
| 303 | ProxyServer proxy_server_; |
| 304 | |
| 305 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 306 | }; |
| 307 | |
| 308 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 309 | public: |
| 310 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 311 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 312 | |
| 313 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 314 | std::unique_ptr<ProxyResolver>* resolver, |
| 315 | CompletionOnceCallback callback, |
| 316 | std::unique_ptr<Request>* request) override { |
| 317 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
| 318 | return OK; |
| 319 | } |
| 320 | |
| 321 | private: |
| 322 | ProxyResolver* resolver_; |
| 323 | }; |
| 324 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 325 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 326 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 327 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 328 | } |
| 329 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 330 | class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 331 | public: |
| 332 | FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 333 | |
| 334 | // ProxyResolverFactory override. |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 335 | int CreateProxyResolver(const scoped_refptr<PacFileData>& script_data, |
| 336 | std::unique_ptr<ProxyResolver>* result, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 337 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 338 | std::unique_ptr<Request>* request) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 339 | return ERR_PAC_SCRIPT_FAILED; |
| 340 | } |
| 341 | }; |
| 342 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 343 | class TestSSLConfigService : public SSLConfigService { |
| 344 | public: |
| 345 | explicit TestSSLConfigService(const SSLConfig& config) : config_(config) {} |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 346 | ~TestSSLConfigService() override = default; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 347 | |
| 348 | void GetSSLConfig(SSLConfig* config) override { *config = config_; } |
| 349 | |
Nick Harper | 89bc721 | 2018-07-31 19:07:57 | [diff] [blame] | 350 | bool CanShareConnectionWithClientCerts( |
| 351 | const std::string& hostname) const override { |
| 352 | return false; |
| 353 | } |
| 354 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 355 | private: |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 356 | SSLConfig config_; |
| 357 | }; |
| 358 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 359 | } // namespace |
| 360 | |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 361 | class HttpNetworkTransactionTest : public PlatformTest, |
| 362 | public WithScopedTaskEnvironment { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 363 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 364 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 365 | // Important to restore the per-pool limit first, since the pool limit must |
| 366 | // always be greater than group limit, and the tests reduce both limits. |
| 367 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 368 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 369 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 370 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 371 | } |
| 372 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 373 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 374 | HttpNetworkTransactionTest() |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 375 | : WithScopedTaskEnvironment( |
| 376 | base::test::ScopedTaskEnvironment::MainThreadType::IO_MOCK_TIME, |
| 377 | base::test::ScopedTaskEnvironment::NowSource:: |
| 378 | MAIN_THREAD_MOCK_TIME), |
| 379 | ssl_(ASYNC, OK), |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 380 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 381 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 382 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 383 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 384 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 385 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 386 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 387 | struct SimpleGetHelperResult { |
| 388 | int rv; |
| 389 | std::string status_line; |
| 390 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 391 | int64_t total_received_bytes; |
| 392 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 393 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 394 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 395 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 396 | }; |
| 397 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 398 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 399 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 400 | base::RunLoop().RunUntilIdle(); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 401 | // Set an initial delay to ensure that the first call to TimeTicks::Now() |
| 402 | // before incrementing the counter does not return a null value. |
| 403 | FastForwardBy(TimeDelta::FromSeconds(1)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 404 | } |
| 405 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 406 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 407 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 408 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 409 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 410 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 411 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 412 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 413 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 414 | } |
| 415 | |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 416 | void Check100ResponseTiming(bool use_spdy); |
| 417 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 418 | // Either |write_failure| specifies a write failure or |read_failure| |
| 419 | // specifies a read failure when using a reused socket. In either case, the |
| 420 | // failure should cause the network transaction to resend the request, and the |
| 421 | // other argument should be NULL. |
| 422 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 423 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 424 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 425 | // Either |write_failure| specifies a write failure or |read_failure| |
| 426 | // specifies a read failure when using a reused socket. In either case, the |
| 427 | // failure should cause the network transaction to resend the request, and the |
| 428 | // other argument should be NULL. |
| 429 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 430 | const MockRead* read_failure, |
| 431 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 432 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 433 | SimpleGetHelperResult SimpleGetHelperForData( |
| 434 | base::span<StaticSocketDataProvider*> providers) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 435 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 436 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 437 | HttpRequestInfo request; |
| 438 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 439 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 440 | request.traffic_annotation = |
| 441 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 442 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 443 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 444 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 445 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 446 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 447 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 448 | for (auto* provider : providers) { |
| 449 | session_deps_.socket_factory->AddSocketDataProvider(provider); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 450 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 451 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 452 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 453 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 454 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 455 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 456 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 457 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 458 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 459 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 460 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 461 | |
| 462 | // Even in the failure cases that use this function, connections are always |
| 463 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 464 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 465 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 466 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 467 | if (out.rv != OK) |
| 468 | return out; |
| 469 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 470 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 471 | // Can't use ASSERT_* inside helper functions like this, so |
| 472 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 473 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 474 | out.rv = ERR_UNEXPECTED; |
| 475 | return out; |
| 476 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 477 | out.status_line = response->headers->GetStatusLine(); |
| 478 | |
Tsuyoshi Horo | 01faed6 | 2019-02-20 22:11:37 | [diff] [blame] | 479 | EXPECT_EQ("127.0.0.1", response->remote_endpoint.ToStringWithoutPort()); |
| 480 | EXPECT_EQ(80, response->remote_endpoint.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 481 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 482 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 483 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 484 | EXPECT_EQ(got_endpoint, |
| 485 | out.remote_endpoint_after_start.address().size() > 0); |
| 486 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 487 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 488 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 489 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 490 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 491 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 492 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 493 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 494 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 495 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 496 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 497 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 498 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 499 | std::string line; |
| 500 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 501 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 502 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 503 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 504 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 505 | std::string value; |
| 506 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 507 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 508 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 509 | EXPECT_EQ("keep-alive", value); |
| 510 | |
| 511 | std::string response_headers; |
| 512 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 513 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 514 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 515 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 516 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 517 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 518 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 519 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 520 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 521 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 522 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 523 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 524 | SimpleGetHelperResult SimpleGetHelper(base::span<const MockRead> data_reads) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 525 | MockWrite data_writes[] = { |
| 526 | MockWrite("GET / HTTP/1.1\r\n" |
| 527 | "Host: www.example.org\r\n" |
| 528 | "Connection: keep-alive\r\n\r\n"), |
| 529 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 530 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 531 | StaticSocketDataProvider reads(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 532 | StaticSocketDataProvider* data[] = {&reads}; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 533 | SimpleGetHelperResult out = SimpleGetHelperForData(data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 534 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 535 | EXPECT_EQ(CountWriteBytes(data_writes), out.total_sent_bytes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 536 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 537 | } |
| 538 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 539 | void AddSSLSocketData() { |
| 540 | ssl_.next_proto = kProtoHTTP2; |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 541 | ssl_.ssl_info.cert = |
| 542 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 543 | ASSERT_TRUE(ssl_.ssl_info.cert); |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 544 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 545 | } |
| 546 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 547 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 548 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 549 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 550 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 551 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 552 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 553 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 554 | // These clocks are defined here, even though they're only used in the |
| 555 | // Reporting tests below, since they need to be destroyed after |
| 556 | // |session_deps_|. |
| 557 | base::SimpleTestClock clock_; |
| 558 | base::SimpleTestTickClock tick_clock_; |
| 559 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 560 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 561 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 562 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 563 | |
| 564 | // Original socket limits. Some tests set these. Safest to always restore |
| 565 | // them once each test has been run. |
| 566 | int old_max_group_sockets_; |
| 567 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 568 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 569 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 570 | namespace { |
| 571 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 572 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 573 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 574 | BeforeHeadersSentHandler() |
| 575 | : observed_before_headers_sent_with_proxy_(false), |
| 576 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 577 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 578 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 579 | HttpRequestHeaders* request_headers) { |
| 580 | observed_before_headers_sent_ = true; |
| 581 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 582 | !proxy_info.is_quic()) { |
| 583 | return; |
| 584 | } |
| 585 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 586 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 587 | } |
| 588 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 589 | bool observed_before_headers_sent_with_proxy() const { |
| 590 | return observed_before_headers_sent_with_proxy_; |
| 591 | } |
| 592 | |
| 593 | bool observed_before_headers_sent() const { |
| 594 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | std::string observed_proxy_server_uri() const { |
| 598 | return observed_proxy_server_uri_; |
| 599 | } |
| 600 | |
| 601 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 602 | bool observed_before_headers_sent_with_proxy_; |
| 603 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 604 | std::string observed_proxy_server_uri_; |
| 605 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 606 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 607 | }; |
| 608 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 609 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 610 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 611 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 612 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 613 | const int sizeof_row = strlen(row); |
| 614 | const int num_rows = static_cast<int>( |
| 615 | ceil(static_cast<float>(size) / sizeof_row)); |
| 616 | const int sizeof_data = num_rows * sizeof_row; |
| 617 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 618 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 619 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 620 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 621 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 622 | } |
| 623 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 624 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 625 | uint64_t MockGetMSTime() { |
| 626 | // Tue, 23 May 2017 20:13:07 +0000 |
| 627 | return 131400439870000000; |
| 628 | } |
| 629 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 630 | // Alternative functions that eliminate randomness and dependency on the local |
| 631 | // host name so that the generated NTLM messages are reproducible. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 632 | void MockGenerateRandom(uint8_t* output, size_t n) { |
| 633 | // This is set to 0xaa because the client challenge for testing in |
| 634 | // [MS-NLMP] Section 4.2.1 is 8 bytes of 0xaa. |
| 635 | memset(output, 0xaa, n); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 636 | } |
| 637 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 638 | std::string MockGetHostName() { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 639 | return ntlm::test::kHostnameAscii; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 640 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 641 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 642 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 643 | template<typename ParentPool> |
| 644 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 645 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 646 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 647 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 648 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 649 | const std::string last_group_name_received() const { |
| 650 | return last_group_name_; |
| 651 | } |
| 652 | |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 653 | bool socket_requested() const { return socket_requested_; } |
| 654 | |
Matt Menke | 28ac03e | 2019-02-25 22:25:50 | [diff] [blame] | 655 | int RequestSocket( |
| 656 | const std::string& group_name, |
| 657 | const void* socket_params, |
| 658 | RequestPriority priority, |
| 659 | const SocketTag& socket_tag, |
| 660 | ClientSocketPool::RespectLimits respect_limits, |
| 661 | ClientSocketHandle* handle, |
| 662 | CompletionOnceCallback callback, |
| 663 | const ClientSocketPool::ProxyAuthCallback& proxy_auth_callback, |
| 664 | const NetLogWithSource& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 665 | last_group_name_ = group_name; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 666 | socket_requested_ = true; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 667 | return ERR_IO_PENDING; |
| 668 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 669 | void CancelRequest(const std::string& group_name, |
| 670 | ClientSocketHandle* handle) override {} |
| 671 | void ReleaseSocket(const std::string& group_name, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 672 | std::unique_ptr<StreamSocket> socket, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 673 | int id) override {} |
| 674 | void CloseIdleSockets() override {} |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 675 | void CloseIdleSocketsInGroup(const std::string& group_name) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 676 | int IdleSocketCount() const override { return 0; } |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 677 | size_t IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 678 | return 0; |
| 679 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 680 | LoadState GetLoadState(const std::string& group_name, |
| 681 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 682 | return LOAD_STATE_IDLE; |
| 683 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 684 | |
| 685 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 686 | std::string last_group_name_; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 687 | bool socket_requested_ = false; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 688 | }; |
| 689 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 690 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 691 | CaptureGroupNameTransportSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 692 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 693 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 694 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 695 | HostResolver* host_resolver, |
| 696 | CertVerifier* /* cert_verifier */) |
Matt Menke | cb77b540 | 2019-01-28 17:11:23 | [diff] [blame] | 697 | : ParentPool(0, |
| 698 | 0, |
Tarun Bansal | a763509 | 2019-02-20 10:00:59 | [diff] [blame] | 699 | base::TimeDelta(), |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 700 | nullptr, |
Matt Menke | cb77b540 | 2019-01-28 17:11:23 | [diff] [blame] | 701 | host_resolver, |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 702 | nullptr, |
| 703 | nullptr, |
| 704 | nullptr, |
| 705 | nullptr, |
| 706 | nullptr, |
| 707 | nullptr, |
| 708 | nullptr, |
| 709 | nullptr, |
| 710 | nullptr, |
| 711 | nullptr, |
| 712 | nullptr, |
| 713 | nullptr, |
| 714 | nullptr) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 715 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 716 | //----------------------------------------------------------------------------- |
| 717 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 718 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 719 | // configured for common cases. |
| 720 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 721 | if (!auth_challenge) |
| 722 | return false; |
| 723 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 724 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 725 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 726 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 727 | return true; |
| 728 | } |
| 729 | |
| 730 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 731 | if (!auth_challenge) |
| 732 | return false; |
| 733 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 734 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 735 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 736 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 737 | return true; |
| 738 | } |
| 739 | |
| 740 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 741 | if (!auth_challenge) |
| 742 | return false; |
| 743 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 744 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 745 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 746 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 747 | return true; |
| 748 | } |
| 749 | |
| 750 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 751 | if (!auth_challenge) |
| 752 | return false; |
| 753 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 754 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 755 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 756 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 757 | return true; |
| 758 | } |
| 759 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 760 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 761 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 762 | if (!auth_challenge) |
| 763 | return false; |
| 764 | EXPECT_FALSE(auth_challenge->is_proxy); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 765 | EXPECT_EQ("https://server", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 766 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 767 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 768 | return true; |
| 769 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 770 | |
| 771 | bool CheckNTLMProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 772 | if (!auth_challenge) |
| 773 | return false; |
| 774 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 775 | EXPECT_EQ("http://server", auth_challenge->challenger.Serialize()); |
| 776 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 777 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
| 778 | return true; |
| 779 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 780 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 781 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 782 | } // namespace |
| 783 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 784 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 785 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 786 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 787 | } |
| 788 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 789 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 790 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 791 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 792 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 793 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 794 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 795 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 796 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 797 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 798 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 799 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 800 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 801 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 802 | |
| 803 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 804 | } |
| 805 | |
| 806 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 807 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 808 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 809 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 810 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 811 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 812 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 813 | EXPECT_THAT(out.rv, IsOk()); |
| 814 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 815 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 816 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 817 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 818 | } |
| 819 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 820 | // Response with no status line, and a weird port. Should fail by default. |
| 821 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 822 | MockRead data_reads[] = { |
| 823 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 824 | }; |
| 825 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 826 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 827 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 828 | |
| 829 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 830 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 831 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 832 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 833 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 834 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 835 | request.method = "GET"; |
| 836 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 837 | request.traffic_annotation = |
| 838 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 839 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 840 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 841 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 842 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 843 | } |
| 844 | |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 845 | // Tests that request info can be destroyed after the headers phase is complete. |
| 846 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoReadDestroyRequestInfo) { |
| 847 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 848 | auto trans = |
| 849 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 850 | |
| 851 | MockRead data_reads[] = { |
| 852 | MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Connection: keep-alive\r\n"), |
| 853 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, 0), |
| 854 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 855 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 856 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 857 | |
| 858 | TestCompletionCallback callback; |
| 859 | |
| 860 | { |
| 861 | auto request = std::make_unique<HttpRequestInfo>(); |
| 862 | request->method = "GET"; |
| 863 | request->url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 864 | request->traffic_annotation = |
| 865 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 866 | |
| 867 | int rv = |
| 868 | trans->Start(request.get(), callback.callback(), NetLogWithSource()); |
| 869 | |
| 870 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 871 | } // Let request info be destroyed. |
| 872 | |
| 873 | trans.reset(); |
| 874 | } |
| 875 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 876 | // Response with no status line, and a weird port. Option to allow weird ports |
| 877 | // enabled. |
| 878 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 879 | MockRead data_reads[] = { |
| 880 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 881 | }; |
| 882 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 883 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 884 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 885 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 886 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 887 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 888 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 889 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 890 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 891 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 892 | request.method = "GET"; |
| 893 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 894 | request.traffic_annotation = |
| 895 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 896 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 897 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 898 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 899 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 900 | |
| 901 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 902 | ASSERT_TRUE(info->headers); |
| 903 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 904 | |
| 905 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 906 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 907 | } |
| 908 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 909 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 910 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 911 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 912 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 913 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 914 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 915 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 916 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 917 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 918 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 919 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 920 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 921 | } |
| 922 | |
| 923 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 924 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 925 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 926 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 927 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 928 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 929 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 930 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 931 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 932 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 933 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 934 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 935 | } |
| 936 | |
| 937 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 938 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 939 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 940 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 941 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 942 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 943 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 944 | EXPECT_THAT(out.rv, IsOk()); |
| 945 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 946 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 947 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 948 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 949 | } |
| 950 | |
| 951 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 952 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 953 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 954 | MockRead("\n"), |
| 955 | MockRead("\n"), |
| 956 | MockRead("Q"), |
| 957 | MockRead("J"), |
| 958 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 959 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 960 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 961 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 962 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 963 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 964 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 965 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 966 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 970 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 971 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 972 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 973 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 974 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 975 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 976 | EXPECT_THAT(out.rv, IsOk()); |
| 977 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 978 | EXPECT_EQ("HTT", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 979 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 980 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 981 | } |
| 982 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 983 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 984 | // persistent connection. The response should still terminate since a 204 |
| 985 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 986 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 987 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 988 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 989 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 990 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 991 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 992 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 993 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 994 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 995 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 996 | EXPECT_EQ("", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 997 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 998 | int64_t response_size = reads_size - strlen(junk); |
| 999 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1000 | } |
| 1001 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1002 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1003 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1004 | std::string final_chunk = "0\r\n\r\n"; |
| 1005 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 1006 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1007 | MockRead data_reads[] = { |
| 1008 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 1009 | MockRead("5\r\nHello\r\n"), |
| 1010 | MockRead("1\r\n"), |
| 1011 | MockRead(" \r\n"), |
| 1012 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1013 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1014 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1015 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1016 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1017 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1018 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1019 | EXPECT_EQ("Hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1020 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1021 | int64_t response_size = reads_size - extra_data.size(); |
| 1022 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1023 | } |
| 1024 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1025 | // Next tests deal with http://crbug.com/56344. |
| 1026 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1027 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1028 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1029 | MockRead data_reads[] = { |
| 1030 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1031 | MockRead("Content-Length: 10\r\n"), |
| 1032 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1033 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1034 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1035 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1036 | } |
| 1037 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1038 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1039 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1040 | MockRead data_reads[] = { |
| 1041 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1042 | MockRead("Content-Length: 5\r\n"), |
| 1043 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1044 | MockRead("Hello"), |
| 1045 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1046 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1047 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1048 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1049 | EXPECT_EQ("Hello", out.response_data); |
| 1050 | } |
| 1051 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1052 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1053 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1054 | // More than 2 dupes. |
| 1055 | { |
| 1056 | MockRead data_reads[] = { |
| 1057 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1058 | MockRead("Content-Length: 5\r\n"), |
| 1059 | MockRead("Content-Length: 5\r\n"), |
| 1060 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1061 | MockRead("Hello"), |
| 1062 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1063 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1064 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1065 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1066 | EXPECT_EQ("Hello", out.response_data); |
| 1067 | } |
| 1068 | // HTTP/1.0 |
| 1069 | { |
| 1070 | MockRead data_reads[] = { |
| 1071 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1072 | MockRead("Content-Length: 5\r\n"), |
| 1073 | MockRead("Content-Length: 5\r\n"), |
| 1074 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1075 | MockRead("Hello"), |
| 1076 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1077 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1078 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1079 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1080 | EXPECT_EQ("Hello", out.response_data); |
| 1081 | } |
| 1082 | // 2 dupes and one mismatched. |
| 1083 | { |
| 1084 | MockRead data_reads[] = { |
| 1085 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1086 | MockRead("Content-Length: 10\r\n"), |
| 1087 | MockRead("Content-Length: 10\r\n"), |
| 1088 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1089 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1090 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1091 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1092 | } |
| 1093 | } |
| 1094 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1095 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1096 | MultipleContentLengthHeadersTransferEncoding) { |
| 1097 | MockRead data_reads[] = { |
| 1098 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1099 | MockRead("Content-Length: 666\r\n"), |
| 1100 | MockRead("Content-Length: 1337\r\n"), |
| 1101 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1102 | MockRead("5\r\nHello\r\n"), |
| 1103 | MockRead("1\r\n"), |
| 1104 | MockRead(" \r\n"), |
| 1105 | MockRead("5\r\nworld\r\n"), |
| 1106 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1107 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1108 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1109 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1110 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1111 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1112 | EXPECT_EQ("Hello world", out.response_data); |
| 1113 | } |
| 1114 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1115 | // Next tests deal with http://crbug.com/98895. |
| 1116 | |
| 1117 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1118 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1119 | MockRead data_reads[] = { |
| 1120 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1121 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1122 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1123 | MockRead("Hello"), |
| 1124 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1125 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1126 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1127 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1128 | EXPECT_EQ("Hello", out.response_data); |
| 1129 | } |
| 1130 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1131 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1132 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1133 | MockRead data_reads[] = { |
| 1134 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1135 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1136 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1137 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1138 | MockRead("Hello"), |
| 1139 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1140 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1141 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1142 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1143 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1144 | } |
| 1145 | |
| 1146 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1147 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1148 | MockRead data_reads[] = { |
| 1149 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1150 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1151 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1152 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1153 | MockRead("Hello"), |
| 1154 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1155 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1156 | EXPECT_THAT(out.rv, |
| 1157 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1158 | } |
| 1159 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1160 | // Checks that two identical Location headers result in no error. |
| 1161 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1162 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1163 | MockRead data_reads[] = { |
| 1164 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1165 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1166 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1167 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1168 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1169 | }; |
| 1170 | |
| 1171 | HttpRequestInfo request; |
| 1172 | request.method = "GET"; |
| 1173 | request.url = GURL("http://redirect.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1174 | request.traffic_annotation = |
| 1175 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1176 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1177 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1178 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1179 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1180 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1181 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1182 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1183 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1184 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1185 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1186 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1187 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1188 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1189 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1190 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1191 | ASSERT_TRUE(response); |
| 1192 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1193 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1194 | std::string url; |
| 1195 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1196 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1197 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1198 | } |
| 1199 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1200 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1201 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1202 | MockRead data_reads[] = { |
| 1203 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1204 | MockRead("Location: http://good.com/\r\n"), |
| 1205 | MockRead("Location: http://evil.com/\r\n"), |
| 1206 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1207 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1208 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1209 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1210 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1211 | } |
| 1212 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1213 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1214 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1215 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1216 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1217 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1218 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1219 | request.traffic_annotation = |
| 1220 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1221 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1222 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1223 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1224 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1225 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1226 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1227 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1228 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1229 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1230 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1231 | "Host: www.example.org\r\n" |
| 1232 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1233 | }; |
| 1234 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1235 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1236 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1237 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1238 | // No response body because the test stops reading here. |
| 1239 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1240 | }; |
| 1241 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1242 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1243 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1244 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1245 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1246 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1247 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1248 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1249 | |
| 1250 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1251 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1252 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1253 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1254 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1255 | |
| 1256 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1257 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1258 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1259 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1260 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1261 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1262 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1263 | |
| 1264 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1265 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1266 | bool has_server_header = response->headers->EnumerateHeader( |
| 1267 | &iter, "Server", &server_header); |
| 1268 | EXPECT_TRUE(has_server_header); |
| 1269 | EXPECT_EQ("Blah", server_header); |
| 1270 | |
| 1271 | // Reading should give EOF right away, since there is no message body |
| 1272 | // (despite non-zero content-length). |
| 1273 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1274 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1275 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1276 | EXPECT_EQ("", response_data); |
| 1277 | } |
| 1278 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1279 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1280 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1281 | |
| 1282 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1283 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1284 | MockRead("hello"), |
| 1285 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1286 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1287 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1288 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1289 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1290 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1291 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1292 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1293 | "hello", "world" |
| 1294 | }; |
| 1295 | |
| 1296 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1297 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1298 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1299 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1300 | request.traffic_annotation = |
| 1301 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1302 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1303 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1304 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1305 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1306 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1307 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1308 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1309 | |
| 1310 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1311 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1312 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1313 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1314 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1315 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1316 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1317 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1318 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1319 | |
| 1320 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1321 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1322 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1323 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1324 | } |
| 1325 | } |
| 1326 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1327 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1328 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1329 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1330 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1331 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1332 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1333 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1334 | request.method = "POST"; |
| 1335 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1336 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1337 | request.traffic_annotation = |
| 1338 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1339 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1340 | // Check the upload progress returned before initialization is correct. |
| 1341 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1342 | EXPECT_EQ(0u, progress.size()); |
| 1343 | EXPECT_EQ(0u, progress.position()); |
| 1344 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1345 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1346 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1347 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1348 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1349 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1350 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1351 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1352 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1353 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1354 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1355 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1356 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1357 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1358 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1359 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1360 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1361 | |
| 1362 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1363 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1364 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1365 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1366 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1367 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1368 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1369 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1370 | |
| 1371 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1372 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1373 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1374 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1375 | } |
| 1376 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1377 | // This test is almost the same as Ignores100 above, but the response contains |
| 1378 | // 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] | 1379 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1380 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1381 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1382 | request.method = "GET"; |
| 1383 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1384 | request.traffic_annotation = |
| 1385 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1386 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1387 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1388 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1389 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1390 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1391 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1392 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1393 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1394 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1395 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1396 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1397 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1398 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1399 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1400 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1401 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1402 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1403 | |
| 1404 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1405 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1406 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1407 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1408 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1409 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1410 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1411 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1412 | |
| 1413 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1414 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1415 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1416 | EXPECT_EQ("hello world", response_data); |
| 1417 | } |
| 1418 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1419 | TEST_F(HttpNetworkTransactionTest, LoadTimingMeasuresTimeToFirstByteForHttp) { |
| 1420 | static const base::TimeDelta kDelayAfterFirstByte = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1421 | base::TimeDelta::FromMilliseconds(10); |
| 1422 | |
| 1423 | HttpRequestInfo request; |
| 1424 | request.method = "GET"; |
| 1425 | request.url = GURL("http://www.foo.com/"); |
| 1426 | request.traffic_annotation = |
| 1427 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1428 | |
| 1429 | std::vector<MockWrite> data_writes = { |
| 1430 | MockWrite(ASYNC, 0, |
| 1431 | "GET / HTTP/1.1\r\n" |
| 1432 | "Host: www.foo.com\r\n" |
| 1433 | "Connection: keep-alive\r\n\r\n"), |
| 1434 | }; |
| 1435 | |
| 1436 | std::vector<MockRead> data_reads = { |
| 1437 | // Write one byte of the status line, followed by a pause. |
| 1438 | MockRead(ASYNC, 1, "H"), |
| 1439 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1440 | MockRead(ASYNC, 3, "TTP/1.1 200 OK\r\n\r\n"), |
| 1441 | MockRead(ASYNC, 4, "hello world"), |
| 1442 | MockRead(SYNCHRONOUS, OK, 5), |
| 1443 | }; |
| 1444 | |
| 1445 | SequencedSocketData data(data_reads, data_writes); |
| 1446 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1447 | |
| 1448 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1449 | |
| 1450 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1451 | |
| 1452 | TestCompletionCallback callback; |
| 1453 | |
| 1454 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1455 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1456 | |
| 1457 | data.RunUntilPaused(); |
| 1458 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1459 | FastForwardBy(kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1460 | data.Resume(); |
| 1461 | |
| 1462 | rv = callback.WaitForResult(); |
| 1463 | EXPECT_THAT(rv, IsOk()); |
| 1464 | |
| 1465 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1466 | ASSERT_TRUE(response); |
| 1467 | |
| 1468 | EXPECT_TRUE(response->headers); |
| 1469 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1470 | |
| 1471 | LoadTimingInfo load_timing_info; |
| 1472 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1473 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1474 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1475 | // Ensure we didn't include the delay in the TTFB time. |
| 1476 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1477 | load_timing_info.connect_timing.connect_end); |
| 1478 | // Ensure that the mock clock advanced at all. |
| 1479 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1480 | kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1481 | |
| 1482 | std::string response_data; |
| 1483 | rv = ReadTransaction(&trans, &response_data); |
| 1484 | EXPECT_THAT(rv, IsOk()); |
| 1485 | EXPECT_EQ("hello world", response_data); |
| 1486 | } |
| 1487 | |
| 1488 | // Tests that the time-to-first-byte reported in a transaction's load timing |
| 1489 | // info uses the first response, even if 1XX/informational. |
| 1490 | void HttpNetworkTransactionTest::Check100ResponseTiming(bool use_spdy) { |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1491 | static const base::TimeDelta kDelayAfter100Response = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1492 | base::TimeDelta::FromMilliseconds(10); |
| 1493 | |
| 1494 | HttpRequestInfo request; |
| 1495 | request.method = "GET"; |
| 1496 | request.url = GURL("https://www.foo.com/"); |
| 1497 | request.traffic_annotation = |
| 1498 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1499 | |
| 1500 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 1501 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 1502 | |
| 1503 | std::vector<MockWrite> data_writes; |
| 1504 | std::vector<MockRead> data_reads; |
| 1505 | |
| 1506 | spdy::SpdySerializedFrame spdy_req( |
| 1507 | spdy_util_.ConstructSpdyGet(request.url.spec().c_str(), 1, LOWEST)); |
| 1508 | |
| 1509 | spdy::SpdyHeaderBlock spdy_resp1_headers; |
| 1510 | spdy_resp1_headers[spdy::kHttp2StatusHeader] = "100"; |
| 1511 | spdy::SpdySerializedFrame spdy_resp1( |
| 1512 | spdy_util_.ConstructSpdyReply(1, spdy_resp1_headers.Clone())); |
| 1513 | spdy::SpdySerializedFrame spdy_resp2( |
| 1514 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1515 | spdy::SpdySerializedFrame spdy_data( |
| 1516 | spdy_util_.ConstructSpdyDataFrame(1, "hello world", true)); |
| 1517 | |
| 1518 | if (use_spdy) { |
| 1519 | ssl.next_proto = kProtoHTTP2; |
| 1520 | |
| 1521 | data_writes = {CreateMockWrite(spdy_req, 0)}; |
| 1522 | |
| 1523 | data_reads = { |
| 1524 | CreateMockRead(spdy_resp1, 1), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1525 | CreateMockRead(spdy_resp2, 3), CreateMockRead(spdy_data, 4), |
| 1526 | MockRead(SYNCHRONOUS, OK, 5), |
| 1527 | }; |
| 1528 | } else { |
| 1529 | data_writes = { |
| 1530 | MockWrite(ASYNC, 0, |
| 1531 | "GET / HTTP/1.1\r\n" |
| 1532 | "Host: www.foo.com\r\n" |
| 1533 | "Connection: keep-alive\r\n\r\n"), |
| 1534 | }; |
| 1535 | |
| 1536 | data_reads = { |
| 1537 | MockRead(ASYNC, 1, "HTTP/1.1 100 Continue\r\n\r\n"), |
| 1538 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1539 | |
| 1540 | MockRead(ASYNC, 3, "HTTP/1.1 200 OK\r\n\r\n"), |
| 1541 | MockRead(ASYNC, 4, "hello world"), |
| 1542 | MockRead(SYNCHRONOUS, OK, 5), |
| 1543 | }; |
| 1544 | } |
| 1545 | |
| 1546 | SequencedSocketData data(data_reads, data_writes); |
| 1547 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1548 | |
| 1549 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1550 | |
| 1551 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1552 | |
| 1553 | TestCompletionCallback callback; |
| 1554 | |
| 1555 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1556 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1557 | |
| 1558 | data.RunUntilPaused(); |
| 1559 | // We should now have parsed the 100 response and hit ERR_IO_PENDING. Insert |
| 1560 | // the delay before parsing the 200 response. |
| 1561 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1562 | FastForwardBy(kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1563 | data.Resume(); |
| 1564 | |
| 1565 | rv = callback.WaitForResult(); |
| 1566 | EXPECT_THAT(rv, IsOk()); |
| 1567 | |
| 1568 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1569 | ASSERT_TRUE(response); |
| 1570 | |
| 1571 | LoadTimingInfo load_timing_info; |
| 1572 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1573 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1574 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1575 | // Ensure we didn't include the delay in the TTFB time. |
| 1576 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1577 | load_timing_info.connect_timing.connect_end); |
| 1578 | // Ensure that the mock clock advanced at all. |
| 1579 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1580 | kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1581 | |
| 1582 | std::string response_data; |
| 1583 | rv = ReadTransaction(&trans, &response_data); |
| 1584 | EXPECT_THAT(rv, IsOk()); |
| 1585 | EXPECT_EQ("hello world", response_data); |
| 1586 | } |
| 1587 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1588 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForHttp) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1589 | Check100ResponseTiming(false /* use_spdy */); |
| 1590 | } |
| 1591 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1592 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForSpdy) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1593 | Check100ResponseTiming(true /* use_spdy */); |
| 1594 | } |
| 1595 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1596 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1597 | HttpRequestInfo request; |
| 1598 | request.method = "POST"; |
| 1599 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1600 | request.traffic_annotation = |
| 1601 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1602 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1603 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1604 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1605 | |
| 1606 | MockRead data_reads[] = { |
| 1607 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1608 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1609 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1610 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1611 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1612 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1613 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1614 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1615 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1616 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1617 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1618 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1619 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1620 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1621 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1622 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1623 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1624 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1625 | } |
| 1626 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1627 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1628 | HttpRequestInfo request; |
| 1629 | request.method = "POST"; |
| 1630 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1631 | request.traffic_annotation = |
| 1632 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1633 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1634 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1635 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1636 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1637 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1638 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1639 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1640 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1641 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1642 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1643 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1644 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1645 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1646 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1647 | |
| 1648 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1649 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1650 | } |
| 1651 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1652 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1653 | const MockWrite* write_failure, |
| 1654 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1655 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1656 | request.method = "GET"; |
| 1657 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1658 | request.traffic_annotation = |
| 1659 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1660 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1661 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1662 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1663 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1664 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1665 | // Written data for successfully sending both requests. |
| 1666 | MockWrite data1_writes[] = { |
| 1667 | MockWrite("GET / HTTP/1.1\r\n" |
| 1668 | "Host: www.foo.com\r\n" |
| 1669 | "Connection: keep-alive\r\n\r\n"), |
| 1670 | MockWrite("GET / HTTP/1.1\r\n" |
| 1671 | "Host: www.foo.com\r\n" |
| 1672 | "Connection: keep-alive\r\n\r\n") |
| 1673 | }; |
| 1674 | |
| 1675 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1676 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1677 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1678 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1679 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1680 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1681 | |
| 1682 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1683 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1684 | data1_writes[1] = *write_failure; |
| 1685 | } else { |
| 1686 | ASSERT_TRUE(read_failure); |
| 1687 | data1_reads[2] = *read_failure; |
| 1688 | } |
| 1689 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1690 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1691 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1692 | |
| 1693 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1694 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1695 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1696 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1697 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1698 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1699 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1700 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1701 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1702 | "hello", "world" |
| 1703 | }; |
| 1704 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1705 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1706 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1707 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1708 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1709 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1710 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1711 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1712 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1713 | |
| 1714 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1715 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1716 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1717 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1718 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1719 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1720 | if (i == 0) { |
| 1721 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1722 | } else { |
| 1723 | // The second request should be using a new socket. |
| 1724 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1725 | } |
| 1726 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1727 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1728 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1729 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1730 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1731 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1732 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1733 | |
| 1734 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1735 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1736 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1737 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1738 | } |
| 1739 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1740 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1741 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1742 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1743 | const MockRead* read_failure, |
| 1744 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1745 | HttpRequestInfo request; |
| 1746 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1747 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1748 | request.traffic_annotation = |
| 1749 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1750 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1751 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1752 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1753 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1754 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1755 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1756 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1757 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1758 | ssl1.next_proto = kProtoHTTP2; |
| 1759 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1760 | } |
| 1761 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1762 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1763 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1764 | // SPDY versions of the request and response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1765 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1766 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1767 | spdy::SpdySerializedFrame spdy_response( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 1768 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1769 | spdy::SpdySerializedFrame spdy_data( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 1770 | spdy_util_.ConstructSpdyDataFrame(1, "hello", true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1771 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1772 | // HTTP/1.1 versions of the request and response. |
| 1773 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1774 | "Host: www.foo.com\r\n" |
| 1775 | "Connection: keep-alive\r\n\r\n"; |
| 1776 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1777 | const char kHttpData[] = "hello"; |
| 1778 | |
| 1779 | std::vector<MockRead> data1_reads; |
| 1780 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1781 | if (write_failure) { |
| 1782 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1783 | data1_writes.push_back(*write_failure); |
| 1784 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1785 | } else { |
| 1786 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1787 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1788 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1789 | } else { |
| 1790 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1791 | } |
| 1792 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1793 | } |
| 1794 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1795 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1796 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1797 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1798 | std::vector<MockRead> data2_reads; |
| 1799 | std::vector<MockWrite> data2_writes; |
| 1800 | |
| 1801 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1802 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1803 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1804 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1805 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1806 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1807 | } else { |
| 1808 | data2_writes.push_back( |
| 1809 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1810 | |
| 1811 | data2_reads.push_back( |
| 1812 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1813 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1814 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1815 | } |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1816 | SequencedSocketData data2(data2_reads, data2_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1817 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1818 | |
| 1819 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1820 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1821 | // Wait for the preconnect to complete. |
| 1822 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1823 | base::RunLoop().RunUntilIdle(); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 1824 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1825 | |
| 1826 | // Make the request. |
| 1827 | TestCompletionCallback callback; |
| 1828 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1829 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1830 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1831 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1832 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1833 | |
| 1834 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1835 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1836 | |
| 1837 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1838 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1839 | TestLoadTimingNotReused( |
| 1840 | load_timing_info, |
| 1841 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1842 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1843 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1844 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1845 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1846 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1847 | if (response->was_fetched_via_spdy) { |
| 1848 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1849 | } else { |
| 1850 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1851 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1852 | |
| 1853 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1854 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1855 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1856 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1857 | } |
| 1858 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1859 | // Test that we do not retry indefinitely when a server sends an error like |
| 1860 | // ERR_SPDY_PING_FAILED, ERR_SPDY_SERVER_REFUSED_STREAM, |
| 1861 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1862 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1863 | HttpRequestInfo request; |
| 1864 | request.method = "GET"; |
| 1865 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1866 | request.traffic_annotation = |
| 1867 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1868 | |
| 1869 | // Check whether we give up after the third try. |
| 1870 | |
| 1871 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1872 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1873 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1874 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1875 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1876 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1877 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1878 | |
| 1879 | // Three go away responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1880 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1881 | StaticSocketDataProvider data2(data_read1, data_write); |
| 1882 | StaticSocketDataProvider data3(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1883 | |
| 1884 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1885 | AddSSLSocketData(); |
| 1886 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1887 | AddSSLSocketData(); |
| 1888 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1889 | AddSSLSocketData(); |
| 1890 | |
| 1891 | TestCompletionCallback callback; |
| 1892 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1893 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1894 | |
| 1895 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1896 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1897 | |
| 1898 | rv = callback.WaitForResult(); |
| 1899 | EXPECT_THAT(rv, IsError(ERR_SPDY_SERVER_REFUSED_STREAM)); |
| 1900 | } |
| 1901 | |
| 1902 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1903 | HttpRequestInfo request; |
| 1904 | request.method = "GET"; |
| 1905 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1906 | request.traffic_annotation = |
| 1907 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1908 | |
| 1909 | // Check whether we try atleast thrice before giving up. |
| 1910 | |
| 1911 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1912 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1913 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1914 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1915 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1916 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1917 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1918 | |
| 1919 | // Construct a non error HTTP2 response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1920 | spdy::SpdySerializedFrame spdy_response_no_error( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1921 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1922 | spdy::SpdySerializedFrame spdy_data( |
| 1923 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1924 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1925 | CreateMockRead(spdy_data, 2)}; |
| 1926 | |
| 1927 | // Two error responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1928 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1929 | StaticSocketDataProvider data2(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1930 | // Followed by a success response. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1931 | SequencedSocketData data3(data_read2, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1932 | |
| 1933 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1934 | AddSSLSocketData(); |
| 1935 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1936 | AddSSLSocketData(); |
| 1937 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1938 | AddSSLSocketData(); |
| 1939 | |
| 1940 | TestCompletionCallback callback; |
| 1941 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1942 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1943 | |
| 1944 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1945 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1946 | |
| 1947 | rv = callback.WaitForResult(); |
| 1948 | EXPECT_THAT(rv, IsOk()); |
| 1949 | } |
| 1950 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1951 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1952 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 1953 | KeepAliveConnectionResendRequestTest(&write_failure, nullptr); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1954 | } |
| 1955 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1956 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1957 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 1958 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1959 | } |
| 1960 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1961 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1962 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 1963 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1964 | } |
| 1965 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1966 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1967 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1968 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1969 | MockRead read_failure(SYNCHRONOUS, |
| 1970 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1971 | "Connection: Keep-Alive\r\n" |
| 1972 | "Content-Length: 6\r\n\r\n" |
| 1973 | "Pickle"); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 1974 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1975 | } |
| 1976 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1977 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1978 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 1979 | PreconnectErrorResendRequestTest(&write_failure, nullptr, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1980 | } |
| 1981 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1982 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1983 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 1984 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1985 | } |
| 1986 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1987 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1988 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 1989 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1990 | } |
| 1991 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1992 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1993 | MockRead read_failure(ASYNC, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 1994 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1995 | } |
| 1996 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1997 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1998 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1999 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2000 | MockRead read_failure(SYNCHRONOUS, |
| 2001 | "HTTP/1.1 408 Request Timeout\r\n" |
| 2002 | "Connection: Keep-Alive\r\n" |
| 2003 | "Content-Length: 6\r\n\r\n" |
| 2004 | "Pickle"); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 2005 | KeepAliveConnectionResendRequestTest(nullptr, &read_failure); |
| 2006 | PreconnectErrorResendRequestTest(nullptr, &read_failure, false); |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2007 | } |
| 2008 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2009 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2010 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 2011 | PreconnectErrorResendRequestTest(&write_failure, nullptr, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2012 | } |
| 2013 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2014 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2015 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 2016 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2017 | } |
| 2018 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2019 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2020 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 2021 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2022 | } |
| 2023 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2024 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2025 | MockRead read_failure(ASYNC, OK); // EOF |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 2026 | PreconnectErrorResendRequestTest(nullptr, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2027 | } |
| 2028 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2029 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2030 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2031 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2032 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2033 | request.traffic_annotation = |
| 2034 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2035 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2036 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2037 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2038 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2039 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2040 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2041 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2042 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2043 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2044 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2045 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2046 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2047 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2048 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2049 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2050 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2051 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2052 | |
| 2053 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2054 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2055 | |
| 2056 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2057 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2058 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2059 | } |
| 2060 | |
| 2061 | // What do various browsers do when the server closes a non-keepalive |
| 2062 | // connection without sending any response header or body? |
| 2063 | // |
| 2064 | // IE7: error page |
| 2065 | // Safari 3.1.2 (Windows): error page |
| 2066 | // Firefox 3.0.1: blank page |
| 2067 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2068 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 2069 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2070 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2071 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2072 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2073 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2074 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2075 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2076 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2077 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2078 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2079 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 2080 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2081 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 2082 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 2083 | // destructor in such situations. |
| 2084 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2085 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2086 | HttpRequestInfo request; |
| 2087 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2088 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2089 | request.traffic_annotation = |
| 2090 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2091 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2092 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2093 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2094 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2095 | |
| 2096 | MockRead data_reads[] = { |
| 2097 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2098 | MockRead("Connection: keep-alive\r\n"), |
| 2099 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2100 | MockRead("hello"), |
| 2101 | MockRead(SYNCHRONOUS, 0), |
| 2102 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2103 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2104 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2105 | |
| 2106 | TestCompletionCallback callback; |
| 2107 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2108 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2109 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2110 | |
| 2111 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2112 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2113 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2114 | scoped_refptr<IOBufferWithSize> io_buf = |
| 2115 | base::MakeRefCounted<IOBufferWithSize>(100); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2116 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2117 | if (rv == ERR_IO_PENDING) |
| 2118 | rv = callback.WaitForResult(); |
| 2119 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2120 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2121 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2122 | |
| 2123 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2124 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2125 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2126 | } |
| 2127 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2128 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2129 | HttpRequestInfo request; |
| 2130 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2131 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2132 | request.traffic_annotation = |
| 2133 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2134 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2135 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2136 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2137 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2138 | |
| 2139 | MockRead data_reads[] = { |
| 2140 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2141 | MockRead("Connection: keep-alive\r\n"), |
| 2142 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2143 | MockRead(SYNCHRONOUS, 0), |
| 2144 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2145 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2146 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2147 | |
| 2148 | TestCompletionCallback callback; |
| 2149 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2150 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2151 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2152 | |
| 2153 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2154 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2155 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2156 | scoped_refptr<IOBufferWithSize> io_buf( |
| 2157 | base::MakeRefCounted<IOBufferWithSize>(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2158 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2159 | if (rv == ERR_IO_PENDING) |
| 2160 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2161 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2162 | |
| 2163 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2164 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2165 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2166 | } |
| 2167 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2168 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 2169 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2170 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2171 | HttpRequestInfo request; |
| 2172 | request.method = "GET"; |
| 2173 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2174 | request.traffic_annotation = |
| 2175 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2176 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2177 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2178 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2179 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2180 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2181 | const char* request_data = |
| 2182 | "GET / HTTP/1.1\r\n" |
| 2183 | "Host: www.foo.com\r\n" |
| 2184 | "Connection: keep-alive\r\n\r\n"; |
| 2185 | MockWrite data_writes[] = { |
| 2186 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 2187 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 2188 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 2189 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 2190 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 2191 | }; |
| 2192 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2193 | // Note that because all these reads happen in the same |
| 2194 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 2195 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2196 | MockRead data_reads[] = { |
| 2197 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 2198 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 2199 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 2200 | MockRead(ASYNC, 7, |
| 2201 | "HTTP/1.1 302 Found\r\n" |
| 2202 | "Content-Length: 0\r\n\r\n"), |
| 2203 | MockRead(ASYNC, 9, |
| 2204 | "HTTP/1.1 302 Found\r\n" |
| 2205 | "Content-Length: 5\r\n\r\n" |
| 2206 | "hello"), |
| 2207 | MockRead(ASYNC, 11, |
| 2208 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2209 | "Content-Length: 0\r\n\r\n"), |
| 2210 | MockRead(ASYNC, 13, |
| 2211 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2212 | "Content-Length: 5\r\n\r\n" |
| 2213 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2214 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2215 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 2216 | // the set_busy_before_sync_reads(true) call, while the |
| 2217 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 2218 | // reuseable. See http://crbug.com/544255. |
| 2219 | MockRead(ASYNC, 15, |
| 2220 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2221 | "Content-Length: 5\r\n\r\n"), |
| 2222 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2223 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2224 | MockRead(ASYNC, 18, |
| 2225 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2226 | "Content-Length: 5\r\n\r\n" |
| 2227 | "he"), |
| 2228 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 2229 | |
| 2230 | // The body of the final request is actually read. |
| 2231 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 2232 | MockRead(ASYNC, 22, "hello"), |
| 2233 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2234 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2235 | data.set_busy_before_sync_reads(true); |
| 2236 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2237 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2238 | const int kNumUnreadBodies = base::size(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2239 | std::string response_lines[kNumUnreadBodies]; |
| 2240 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 2241 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2242 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2243 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2244 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2245 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2246 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2247 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2248 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2249 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2250 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2251 | LoadTimingInfo load_timing_info; |
| 2252 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2253 | if (i == 0) { |
| 2254 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2255 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2256 | } else { |
| 2257 | TestLoadTimingReused(load_timing_info); |
| 2258 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2259 | } |
| 2260 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2261 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2262 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2263 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2264 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2265 | response_lines[i] = response->headers->GetStatusLine(); |
| 2266 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2267 | // Delete the transaction without reading the response bodies. Then spin |
| 2268 | // the message loop, so the response bodies are drained. |
| 2269 | trans.reset(); |
| 2270 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2271 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2272 | |
| 2273 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2274 | "HTTP/1.1 204 No Content", |
| 2275 | "HTTP/1.1 205 Reset Content", |
| 2276 | "HTTP/1.1 304 Not Modified", |
| 2277 | "HTTP/1.1 302 Found", |
| 2278 | "HTTP/1.1 302 Found", |
| 2279 | "HTTP/1.1 301 Moved Permanently", |
| 2280 | "HTTP/1.1 301 Moved Permanently", |
| 2281 | "HTTP/1.1 200 Hunky-Dory", |
| 2282 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2283 | }; |
| 2284 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2285 | static_assert(kNumUnreadBodies == base::size(kStatusLines), |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2286 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2287 | |
| 2288 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2289 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2290 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2291 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2292 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2293 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2294 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2295 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2296 | ASSERT_TRUE(response); |
| 2297 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2298 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2299 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2300 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2301 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2302 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2303 | } |
| 2304 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2305 | // Sockets that receive extra data after a response is complete should not be |
| 2306 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2307 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2308 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2309 | MockWrite data_writes1[] = { |
| 2310 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2311 | "Host: www.borked.com\r\n" |
| 2312 | "Connection: keep-alive\r\n\r\n"), |
| 2313 | }; |
| 2314 | |
| 2315 | MockRead data_reads1[] = { |
| 2316 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2317 | "Connection: keep-alive\r\n" |
| 2318 | "Content-Length: 22\r\n\r\n" |
| 2319 | "This server is borked."), |
| 2320 | }; |
| 2321 | |
| 2322 | MockWrite data_writes2[] = { |
| 2323 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2324 | "Host: www.borked.com\r\n" |
| 2325 | "Connection: keep-alive\r\n\r\n"), |
| 2326 | }; |
| 2327 | |
| 2328 | MockRead data_reads2[] = { |
| 2329 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2330 | "Content-Length: 3\r\n\r\n" |
| 2331 | "foo"), |
| 2332 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2333 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2334 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2335 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2336 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2337 | |
| 2338 | TestCompletionCallback callback; |
| 2339 | HttpRequestInfo request1; |
| 2340 | request1.method = "HEAD"; |
| 2341 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2342 | request1.traffic_annotation = |
| 2343 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2344 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2345 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2346 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2347 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2348 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2349 | |
| 2350 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2351 | ASSERT_TRUE(response1); |
| 2352 | ASSERT_TRUE(response1->headers); |
| 2353 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2354 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2355 | |
| 2356 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2357 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2358 | EXPECT_EQ("", response_data1); |
| 2359 | // Deleting the transaction attempts to release the socket back into the |
| 2360 | // socket pool. |
| 2361 | trans1.reset(); |
| 2362 | |
| 2363 | HttpRequestInfo request2; |
| 2364 | request2.method = "GET"; |
| 2365 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2366 | request2.traffic_annotation = |
| 2367 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2368 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2369 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2370 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2371 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2372 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2373 | |
| 2374 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2375 | ASSERT_TRUE(response2); |
| 2376 | ASSERT_TRUE(response2->headers); |
| 2377 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2378 | |
| 2379 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2380 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2381 | EXPECT_EQ("foo", response_data2); |
| 2382 | } |
| 2383 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2384 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2385 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2386 | MockWrite data_writes1[] = { |
| 2387 | MockWrite("GET / HTTP/1.1\r\n" |
| 2388 | "Host: www.borked.com\r\n" |
| 2389 | "Connection: keep-alive\r\n\r\n"), |
| 2390 | }; |
| 2391 | |
| 2392 | MockRead data_reads1[] = { |
| 2393 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2394 | "Connection: keep-alive\r\n" |
| 2395 | "Content-Length: 22\r\n\r\n" |
| 2396 | "This server is borked." |
| 2397 | "Bonus data!"), |
| 2398 | }; |
| 2399 | |
| 2400 | MockWrite data_writes2[] = { |
| 2401 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2402 | "Host: www.borked.com\r\n" |
| 2403 | "Connection: keep-alive\r\n\r\n"), |
| 2404 | }; |
| 2405 | |
| 2406 | MockRead data_reads2[] = { |
| 2407 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2408 | "Content-Length: 3\r\n\r\n" |
| 2409 | "foo"), |
| 2410 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2411 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2412 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2413 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2414 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2415 | |
| 2416 | TestCompletionCallback callback; |
| 2417 | HttpRequestInfo request1; |
| 2418 | request1.method = "GET"; |
| 2419 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2420 | request1.traffic_annotation = |
| 2421 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2422 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2423 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2424 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2425 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2426 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2427 | |
| 2428 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2429 | ASSERT_TRUE(response1); |
| 2430 | ASSERT_TRUE(response1->headers); |
| 2431 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2432 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2433 | |
| 2434 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2435 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2436 | EXPECT_EQ("This server is borked.", response_data1); |
| 2437 | // Deleting the transaction attempts to release the socket back into the |
| 2438 | // socket pool. |
| 2439 | trans1.reset(); |
| 2440 | |
| 2441 | HttpRequestInfo request2; |
| 2442 | request2.method = "GET"; |
| 2443 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2444 | request2.traffic_annotation = |
| 2445 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2446 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2447 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2448 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2449 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2450 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2451 | |
| 2452 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2453 | ASSERT_TRUE(response2); |
| 2454 | ASSERT_TRUE(response2->headers); |
| 2455 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2456 | |
| 2457 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2458 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2459 | EXPECT_EQ("foo", response_data2); |
| 2460 | } |
| 2461 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2462 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2463 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2464 | MockWrite data_writes1[] = { |
| 2465 | MockWrite("GET / HTTP/1.1\r\n" |
| 2466 | "Host: www.borked.com\r\n" |
| 2467 | "Connection: keep-alive\r\n\r\n"), |
| 2468 | }; |
| 2469 | |
| 2470 | MockRead data_reads1[] = { |
| 2471 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2472 | "Connection: keep-alive\r\n" |
| 2473 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2474 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2475 | MockRead("0\r\n\r\nBonus data!"), |
| 2476 | }; |
| 2477 | |
| 2478 | MockWrite data_writes2[] = { |
| 2479 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2480 | "Host: www.borked.com\r\n" |
| 2481 | "Connection: keep-alive\r\n\r\n"), |
| 2482 | }; |
| 2483 | |
| 2484 | MockRead data_reads2[] = { |
| 2485 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2486 | "Content-Length: 3\r\n\r\n" |
| 2487 | "foo"), |
| 2488 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2489 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2490 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2491 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2492 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2493 | |
| 2494 | TestCompletionCallback callback; |
| 2495 | HttpRequestInfo request1; |
| 2496 | request1.method = "GET"; |
| 2497 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2498 | request1.traffic_annotation = |
| 2499 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2500 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2501 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2502 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2503 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2504 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2505 | |
| 2506 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2507 | ASSERT_TRUE(response1); |
| 2508 | ASSERT_TRUE(response1->headers); |
| 2509 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2510 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2511 | |
| 2512 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2513 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2514 | EXPECT_EQ("This server is borked.", response_data1); |
| 2515 | // Deleting the transaction attempts to release the socket back into the |
| 2516 | // socket pool. |
| 2517 | trans1.reset(); |
| 2518 | |
| 2519 | HttpRequestInfo request2; |
| 2520 | request2.method = "GET"; |
| 2521 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2522 | request2.traffic_annotation = |
| 2523 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2524 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2525 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2526 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2527 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2528 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2529 | |
| 2530 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2531 | ASSERT_TRUE(response2); |
| 2532 | ASSERT_TRUE(response2->headers); |
| 2533 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2534 | |
| 2535 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2536 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2537 | EXPECT_EQ("foo", response_data2); |
| 2538 | } |
| 2539 | |
| 2540 | // This is a little different from the others - it tests the case that the |
| 2541 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2542 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2543 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2544 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2545 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2546 | MockWrite data_writes1[] = { |
| 2547 | MockWrite("GET / HTTP/1.1\r\n" |
| 2548 | "Host: www.borked.com\r\n" |
| 2549 | "Connection: keep-alive\r\n\r\n"), |
| 2550 | }; |
| 2551 | |
| 2552 | MockRead data_reads1[] = { |
| 2553 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2554 | "Connection: keep-alive\r\n" |
| 2555 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2556 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2557 | MockRead("0\r\n\r\nBonus data!"), |
| 2558 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2559 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2560 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2561 | |
| 2562 | TestCompletionCallback callback; |
| 2563 | HttpRequestInfo request1; |
| 2564 | request1.method = "GET"; |
| 2565 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2566 | request1.traffic_annotation = |
| 2567 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2568 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2569 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2570 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2571 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2572 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2573 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2574 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2575 | ASSERT_TRUE(response1); |
| 2576 | ASSERT_TRUE(response1->headers); |
| 2577 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2578 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2579 | |
| 2580 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2581 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2582 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2583 | |
| 2584 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2585 | // socket can't be reused, rather than returning it to the socket pool. |
| 2586 | base::RunLoop().RunUntilIdle(); |
| 2587 | |
| 2588 | // There should be no idle sockets in the pool. |
| 2589 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2590 | } |
| 2591 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2592 | // Test the request-challenge-retry sequence for basic auth. |
| 2593 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2594 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2595 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2596 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2597 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2598 | request.traffic_annotation = |
| 2599 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2600 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2601 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2602 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2603 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2604 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2605 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2606 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2607 | MockWrite( |
| 2608 | "GET / HTTP/1.1\r\n" |
| 2609 | "Host: www.example.org\r\n" |
| 2610 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2611 | }; |
| 2612 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2613 | MockRead data_reads1[] = { |
| 2614 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2615 | // Give a couple authenticate options (only the middle one is actually |
| 2616 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2617 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2618 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2619 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2620 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2621 | // Large content-length -- won't matter, as connection will be reset. |
| 2622 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2623 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2624 | }; |
| 2625 | |
| 2626 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2627 | // be issuing -- the final header line contains the credentials. |
| 2628 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2629 | MockWrite( |
| 2630 | "GET / HTTP/1.1\r\n" |
| 2631 | "Host: www.example.org\r\n" |
| 2632 | "Connection: keep-alive\r\n" |
| 2633 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2634 | }; |
| 2635 | |
| 2636 | // Lastly, the server responds with the actual content. |
| 2637 | MockRead data_reads2[] = { |
| 2638 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2639 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2640 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2641 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2642 | }; |
| 2643 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2644 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2645 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2646 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2647 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2648 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2649 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2650 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2651 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2652 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2653 | |
| 2654 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2655 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2656 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2657 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2658 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2659 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2660 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2661 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2662 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2663 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2664 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2665 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2666 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2667 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2668 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2669 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2670 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2671 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2672 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2673 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2674 | |
| 2675 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2676 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2677 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2678 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2679 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2680 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2681 | // The load timing after restart should have a new socket ID, and times after |
| 2682 | // those of the first load timing. |
| 2683 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2684 | load_timing_info2.connect_timing.connect_start); |
| 2685 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2686 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2687 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2688 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2689 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2690 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2691 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2692 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2693 | ASSERT_TRUE(response); |
| 2694 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2695 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2696 | } |
| 2697 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2698 | // Test the request-challenge-retry sequence for basic auth. |
| 2699 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2700 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2701 | HttpRequestInfo request; |
| 2702 | request.method = "GET"; |
| 2703 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2704 | request.traffic_annotation = |
| 2705 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2706 | |
| 2707 | TestNetLog log; |
| 2708 | MockHostResolver* resolver = new MockHostResolver(); |
| 2709 | session_deps_.net_log = &log; |
| 2710 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2711 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2712 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2713 | |
| 2714 | resolver->rules()->ClearRules(); |
| 2715 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2716 | |
| 2717 | MockWrite data_writes1[] = { |
| 2718 | MockWrite("GET / HTTP/1.1\r\n" |
| 2719 | "Host: www.example.org\r\n" |
| 2720 | "Connection: keep-alive\r\n\r\n"), |
| 2721 | }; |
| 2722 | |
| 2723 | MockRead data_reads1[] = { |
| 2724 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2725 | // Give a couple authenticate options (only the middle one is actually |
| 2726 | // supported). |
| 2727 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2728 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2729 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2730 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2731 | // Large content-length -- won't matter, as connection will be reset. |
| 2732 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2733 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2734 | }; |
| 2735 | |
| 2736 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2737 | // be issuing -- the final header line contains the credentials. |
| 2738 | MockWrite data_writes2[] = { |
| 2739 | MockWrite("GET / HTTP/1.1\r\n" |
| 2740 | "Host: www.example.org\r\n" |
| 2741 | "Connection: keep-alive\r\n" |
| 2742 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2743 | }; |
| 2744 | |
| 2745 | // Lastly, the server responds with the actual content. |
| 2746 | MockRead data_reads2[] = { |
| 2747 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2748 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2749 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2750 | }; |
| 2751 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2752 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2753 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2754 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2755 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2756 | |
| 2757 | TestCompletionCallback callback1; |
| 2758 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2759 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2760 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2761 | |
| 2762 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2763 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2764 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2765 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2766 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2767 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2768 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2769 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2770 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2771 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2772 | ASSERT_TRUE(response); |
| 2773 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2774 | |
| 2775 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2776 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2777 | ASSERT_FALSE(endpoint.address().empty()); |
| 2778 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2779 | |
| 2780 | resolver->rules()->ClearRules(); |
| 2781 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2782 | |
| 2783 | TestCompletionCallback callback2; |
| 2784 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2785 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2786 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2787 | |
| 2788 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2789 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2790 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2791 | // The load timing after restart should have a new socket ID, and times after |
| 2792 | // those of the first load timing. |
| 2793 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2794 | load_timing_info2.connect_timing.connect_start); |
| 2795 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2796 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2797 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2798 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2799 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2800 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2801 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2802 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2803 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2804 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2805 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2806 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2807 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2808 | ASSERT_FALSE(endpoint.address().empty()); |
| 2809 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2810 | } |
| 2811 | |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2812 | // Test that, if the server requests auth indefinitely, HttpNetworkTransaction |
| 2813 | // will eventually give up. |
| 2814 | TEST_F(HttpNetworkTransactionTest, BasicAuthForever) { |
| 2815 | HttpRequestInfo request; |
| 2816 | request.method = "GET"; |
| 2817 | request.url = GURL("http://www.example.org/"); |
| 2818 | request.traffic_annotation = |
| 2819 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2820 | |
| 2821 | TestNetLog log; |
| 2822 | session_deps_.net_log = &log; |
| 2823 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2824 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 2825 | |
| 2826 | MockWrite data_writes[] = { |
| 2827 | MockWrite("GET / HTTP/1.1\r\n" |
| 2828 | "Host: www.example.org\r\n" |
| 2829 | "Connection: keep-alive\r\n\r\n"), |
| 2830 | }; |
| 2831 | |
| 2832 | MockRead data_reads[] = { |
| 2833 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2834 | // Give a couple authenticate options (only the middle one is actually |
| 2835 | // supported). |
| 2836 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2837 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2838 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2839 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2840 | // Large content-length -- won't matter, as connection will be reset. |
| 2841 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2842 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2843 | }; |
| 2844 | |
| 2845 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2846 | // be issuing -- the final header line contains the credentials. |
| 2847 | MockWrite data_writes_restart[] = { |
| 2848 | MockWrite("GET / HTTP/1.1\r\n" |
| 2849 | "Host: www.example.org\r\n" |
| 2850 | "Connection: keep-alive\r\n" |
| 2851 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2852 | }; |
| 2853 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2854 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2855 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2856 | |
| 2857 | TestCompletionCallback callback; |
| 2858 | int rv = callback.GetResult( |
| 2859 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 2860 | |
| 2861 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_restarts; |
| 2862 | for (int i = 0; i < 32; i++) { |
| 2863 | // Check the previous response was a 401. |
| 2864 | EXPECT_THAT(rv, IsOk()); |
| 2865 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 2866 | ASSERT_TRUE(response); |
| 2867 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2868 | |
| 2869 | data_restarts.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2870 | data_reads, data_writes_restart)); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2871 | session_deps_.socket_factory->AddSocketDataProvider( |
| 2872 | data_restarts.back().get()); |
| 2873 | rv = callback.GetResult(trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2874 | callback.callback())); |
| 2875 | } |
| 2876 | |
| 2877 | // After too many tries, the transaction should have given up. |
| 2878 | EXPECT_THAT(rv, IsError(ERR_TOO_MANY_RETRIES)); |
| 2879 | } |
| 2880 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2881 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2882 | HttpRequestInfo request; |
| 2883 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2884 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2885 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2886 | request.traffic_annotation = |
| 2887 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2888 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2889 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2890 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2891 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2892 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2893 | MockWrite( |
| 2894 | "GET / HTTP/1.1\r\n" |
| 2895 | "Host: www.example.org\r\n" |
| 2896 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2897 | }; |
| 2898 | |
| 2899 | MockRead data_reads[] = { |
| 2900 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2901 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2902 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2903 | // Large content-length -- won't matter, as connection will be reset. |
| 2904 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2905 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2906 | }; |
| 2907 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2908 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2909 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2910 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2911 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2912 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2913 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2914 | |
| 2915 | rv = callback.WaitForResult(); |
| 2916 | EXPECT_EQ(0, rv); |
| 2917 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2918 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2919 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2920 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2921 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2922 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2923 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2924 | ASSERT_TRUE(response); |
| 2925 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2926 | } |
| 2927 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2928 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2929 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2930 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2931 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2932 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2933 | // reused. See http://crbug.com/544255. |
| 2934 | for (int i = 0; i < 2; ++i) { |
| 2935 | HttpRequestInfo request; |
| 2936 | request.method = "GET"; |
| 2937 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2938 | request.traffic_annotation = |
| 2939 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2940 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2941 | TestNetLog log; |
| 2942 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2943 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2944 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2945 | MockWrite data_writes[] = { |
| 2946 | MockWrite(ASYNC, 0, |
| 2947 | "GET / HTTP/1.1\r\n" |
| 2948 | "Host: www.example.org\r\n" |
| 2949 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2950 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2951 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2952 | // be issuing -- the final header line contains the credentials. |
| 2953 | MockWrite(ASYNC, 6, |
| 2954 | "GET / HTTP/1.1\r\n" |
| 2955 | "Host: www.example.org\r\n" |
| 2956 | "Connection: keep-alive\r\n" |
| 2957 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2958 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2959 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2960 | MockRead data_reads[] = { |
| 2961 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2962 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2963 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2964 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2965 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2966 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2967 | // Lastly, the server responds with the actual content. |
| 2968 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2969 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2970 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2971 | MockRead(ASYNC, 10, "Hello"), |
| 2972 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2973 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2974 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2975 | data.set_busy_before_sync_reads(true); |
| 2976 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2977 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2978 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2979 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2980 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2981 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2982 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2983 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2984 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2985 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2986 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2987 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2988 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2989 | ASSERT_TRUE(response); |
| 2990 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2991 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2992 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2993 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2994 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2995 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2996 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2997 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2998 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2999 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3000 | TestLoadTimingReused(load_timing_info2); |
| 3001 | // The load timing after restart should have the same socket ID, and times |
| 3002 | // those of the first load timing. |
| 3003 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 3004 | load_timing_info2.send_start); |
| 3005 | 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] | 3006 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3007 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3008 | ASSERT_TRUE(response); |
| 3009 | EXPECT_FALSE(response->auth_challenge); |
| 3010 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3011 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3012 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3013 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3014 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3015 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3016 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3017 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3018 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3019 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3020 | } |
| 3021 | |
| 3022 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3023 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3024 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3025 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3026 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3027 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3028 | request.traffic_annotation = |
| 3029 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3030 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3031 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3032 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3033 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3034 | MockWrite("GET / HTTP/1.1\r\n" |
| 3035 | "Host: www.example.org\r\n" |
| 3036 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3037 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3038 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3039 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3040 | MockWrite("GET / HTTP/1.1\r\n" |
| 3041 | "Host: www.example.org\r\n" |
| 3042 | "Connection: keep-alive\r\n" |
| 3043 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3044 | }; |
| 3045 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3046 | MockRead data_reads1[] = { |
| 3047 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3048 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3049 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3050 | |
| 3051 | // Lastly, the server responds with the actual content. |
| 3052 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3053 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3054 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3055 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3056 | }; |
| 3057 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3058 | // An incorrect reconnect would cause this to be read. |
| 3059 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3060 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3061 | }; |
| 3062 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3063 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3064 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3065 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3066 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3067 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3068 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3069 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3070 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3071 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3072 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3073 | |
| 3074 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3075 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3076 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3077 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3078 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3079 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3080 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3081 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3082 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3083 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3084 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3085 | |
| 3086 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3087 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3088 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3089 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3090 | ASSERT_TRUE(response); |
| 3091 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3092 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3093 | } |
| 3094 | |
| 3095 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3096 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3097 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3098 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3099 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3100 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3101 | request.traffic_annotation = |
| 3102 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3103 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3104 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3105 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3106 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3107 | MockWrite("GET / HTTP/1.1\r\n" |
| 3108 | "Host: www.example.org\r\n" |
| 3109 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3110 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3111 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3112 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3113 | MockWrite("GET / HTTP/1.1\r\n" |
| 3114 | "Host: www.example.org\r\n" |
| 3115 | "Connection: keep-alive\r\n" |
| 3116 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3117 | }; |
| 3118 | |
| 3119 | // Respond with 5 kb of response body. |
| 3120 | std::string large_body_string("Unauthorized"); |
| 3121 | large_body_string.append(5 * 1024, ' '); |
| 3122 | large_body_string.append("\r\n"); |
| 3123 | |
| 3124 | MockRead data_reads1[] = { |
| 3125 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3126 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3127 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3128 | // 5134 = 12 + 5 * 1024 + 2 |
| 3129 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3130 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3131 | |
| 3132 | // Lastly, the server responds with the actual content. |
| 3133 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3134 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3135 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3136 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3137 | }; |
| 3138 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3139 | // An incorrect reconnect would cause this to be read. |
| 3140 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3141 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3142 | }; |
| 3143 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3144 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3145 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3146 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3147 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3148 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3149 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3150 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3151 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3152 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3153 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3154 | |
| 3155 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3156 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3157 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3158 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3159 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3160 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3161 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3162 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3163 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3164 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3165 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3166 | |
| 3167 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3168 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3169 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3170 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3171 | ASSERT_TRUE(response); |
| 3172 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3173 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3174 | } |
| 3175 | |
| 3176 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3177 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3178 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3179 | HttpRequestInfo request; |
| 3180 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3181 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3182 | request.traffic_annotation = |
| 3183 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3184 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3185 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3186 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3187 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3188 | MockWrite( |
| 3189 | "GET / HTTP/1.1\r\n" |
| 3190 | "Host: www.example.org\r\n" |
| 3191 | "Connection: keep-alive\r\n\r\n"), |
| 3192 | // This simulates the seemingly successful write to a closed connection |
| 3193 | // if the bug is not fixed. |
| 3194 | MockWrite( |
| 3195 | "GET / HTTP/1.1\r\n" |
| 3196 | "Host: www.example.org\r\n" |
| 3197 | "Connection: keep-alive\r\n" |
| 3198 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3199 | }; |
| 3200 | |
| 3201 | MockRead data_reads1[] = { |
| 3202 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3203 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3204 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3205 | MockRead("Content-Length: 14\r\n\r\n"), |
| 3206 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3207 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3208 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3209 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3210 | }; |
| 3211 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3212 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3213 | // be issuing -- the final header line contains the credentials. |
| 3214 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3215 | MockWrite( |
| 3216 | "GET / HTTP/1.1\r\n" |
| 3217 | "Host: www.example.org\r\n" |
| 3218 | "Connection: keep-alive\r\n" |
| 3219 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3220 | }; |
| 3221 | |
| 3222 | // Lastly, the server responds with the actual content. |
| 3223 | MockRead data_reads2[] = { |
| 3224 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3225 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3226 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3227 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3228 | }; |
| 3229 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3230 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3231 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3232 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3233 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3234 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3235 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3236 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3237 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3238 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3239 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3240 | |
| 3241 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3242 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3243 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3244 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3245 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3246 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3247 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3248 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3249 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3250 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3251 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3252 | |
| 3253 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3254 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3255 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3256 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3257 | ASSERT_TRUE(response); |
| 3258 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3259 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3260 | } |
| 3261 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3262 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3263 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3264 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3265 | HttpRequestInfo request; |
| 3266 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3267 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3268 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3269 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3270 | request.traffic_annotation = |
| 3271 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3272 | |
| 3273 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3274 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3275 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3276 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3277 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3278 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3279 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3280 | |
| 3281 | // Since we have proxy, should try to establish tunnel. |
| 3282 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3283 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3284 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3285 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3286 | }; |
| 3287 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3288 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3289 | // connection. |
| 3290 | MockRead data_reads1[] = { |
| 3291 | // No credentials. |
| 3292 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3293 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3294 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3295 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3296 | // Since the first connection couldn't be reused, need to establish another |
| 3297 | // once given credentials. |
| 3298 | MockWrite data_writes2[] = { |
| 3299 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3300 | // be issuing -- the final header line contains the credentials. |
| 3301 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3302 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3303 | "Proxy-Connection: keep-alive\r\n" |
| 3304 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3305 | |
| 3306 | MockWrite("GET / HTTP/1.1\r\n" |
| 3307 | "Host: www.example.org\r\n" |
| 3308 | "Connection: keep-alive\r\n\r\n"), |
| 3309 | }; |
| 3310 | |
| 3311 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3312 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3313 | |
| 3314 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3315 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3316 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3317 | MockRead(SYNCHRONOUS, "hello"), |
| 3318 | }; |
| 3319 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3320 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3321 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3322 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3323 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3324 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3325 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3326 | |
| 3327 | TestCompletionCallback callback1; |
| 3328 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3329 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3330 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3331 | |
| 3332 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3333 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3334 | |
| 3335 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3336 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3337 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3338 | log.GetEntries(&entries); |
| 3339 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3340 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3341 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3342 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3343 | entries, pos, |
| 3344 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3345 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3346 | |
| 3347 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3348 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3349 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3350 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3351 | EXPECT_EQ(407, response->headers->response_code()); |
| 3352 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3353 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3354 | |
| 3355 | LoadTimingInfo load_timing_info; |
| 3356 | // CONNECT requests and responses are handled at the connect job level, so |
| 3357 | // the transaction does not yet have a connection. |
| 3358 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3359 | |
| 3360 | TestCompletionCallback callback2; |
| 3361 | |
| 3362 | rv = |
| 3363 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3364 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3365 | |
| 3366 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3367 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3368 | |
| 3369 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3370 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3371 | |
| 3372 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3373 | EXPECT_EQ(200, response->headers->response_code()); |
| 3374 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3375 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3376 | |
| 3377 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3378 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3379 | |
| 3380 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3381 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3382 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3383 | |
| 3384 | trans.reset(); |
| 3385 | session->CloseAllConnections(); |
| 3386 | } |
| 3387 | |
| 3388 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3389 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3390 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3391 | HttpRequestInfo request; |
| 3392 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3393 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3394 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3395 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3396 | request.traffic_annotation = |
| 3397 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3398 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3399 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3400 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3401 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3402 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3403 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3404 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3405 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3406 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3407 | // Since we have proxy, should try to establish tunnel. |
| 3408 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3409 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3410 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3411 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3412 | }; |
| 3413 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3414 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3415 | // connection. |
| 3416 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3417 | // No credentials. |
| 3418 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3419 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3420 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3421 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3422 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3423 | MockWrite data_writes2[] = { |
| 3424 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3425 | // be issuing -- the final header line contains the credentials. |
| 3426 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3427 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3428 | "Proxy-Connection: keep-alive\r\n" |
| 3429 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3430 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3431 | MockWrite("GET / HTTP/1.1\r\n" |
| 3432 | "Host: www.example.org\r\n" |
| 3433 | "Connection: keep-alive\r\n\r\n"), |
| 3434 | }; |
| 3435 | |
| 3436 | MockRead data_reads2[] = { |
| 3437 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3438 | |
| 3439 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3440 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3441 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3442 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3443 | }; |
| 3444 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3445 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3446 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3447 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3448 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3449 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3450 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3451 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3452 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3453 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3454 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3455 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3456 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3457 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3458 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3459 | |
| 3460 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3461 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3462 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3463 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3464 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3465 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3466 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3467 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3468 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3469 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3470 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3471 | |
| 3472 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3473 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3474 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3475 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3476 | EXPECT_EQ(407, response->headers->response_code()); |
| 3477 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3478 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3479 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3480 | LoadTimingInfo load_timing_info; |
| 3481 | // CONNECT requests and responses are handled at the connect job level, so |
| 3482 | // the transaction does not yet have a connection. |
| 3483 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3484 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3485 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3486 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3487 | rv = trans->RestartWithAuth( |
| 3488 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3489 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3490 | |
| 3491 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3492 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3493 | |
| 3494 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3495 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3496 | |
| 3497 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3498 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3499 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3500 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3501 | |
| 3502 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3503 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3504 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3505 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3506 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3507 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3508 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3509 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3510 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3511 | } |
| 3512 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3513 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3514 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3515 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3516 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3517 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3518 | // reused. See http://crbug.com/544255. |
| 3519 | for (int i = 0; i < 2; ++i) { |
| 3520 | HttpRequestInfo request; |
| 3521 | request.method = "GET"; |
| 3522 | request.url = GURL("https://www.example.org/"); |
| 3523 | // Ensure that proxy authentication is attempted even |
| 3524 | // when the no authentication data flag is set. |
| 3525 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3526 | request.traffic_annotation = |
| 3527 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3528 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3529 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3530 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3531 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3532 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3533 | BoundTestNetLog log; |
| 3534 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3535 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3536 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3537 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3538 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3539 | // Since we have proxy, should try to establish tunnel. |
| 3540 | MockWrite data_writes1[] = { |
| 3541 | MockWrite(ASYNC, 0, |
| 3542 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3543 | "Host: www.example.org:443\r\n" |
| 3544 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3545 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3546 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3547 | // be issuing -- the final header line contains the credentials. |
| 3548 | MockWrite(ASYNC, 3, |
| 3549 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3550 | "Host: www.example.org:443\r\n" |
| 3551 | "Proxy-Connection: keep-alive\r\n" |
| 3552 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3553 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3554 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3555 | // The proxy responds to the connect with a 407, using a persistent |
| 3556 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3557 | MockRead data_reads1[] = { |
| 3558 | // No credentials. |
| 3559 | MockRead(ASYNC, 1, |
| 3560 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3561 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3562 | "Proxy-Connection: keep-alive\r\n" |
| 3563 | "Content-Length: 10\r\n\r\n"), |
| 3564 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3565 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3566 | // Wrong credentials (wrong password). |
| 3567 | MockRead(ASYNC, 4, |
| 3568 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3569 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3570 | "Proxy-Connection: keep-alive\r\n" |
| 3571 | "Content-Length: 10\r\n\r\n"), |
| 3572 | // No response body because the test stops reading here. |
| 3573 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3574 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3575 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3576 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3577 | data1.set_busy_before_sync_reads(true); |
| 3578 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3579 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3580 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3581 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3582 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3583 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3584 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3585 | TestNetLogEntry::List entries; |
| 3586 | log.GetEntries(&entries); |
| 3587 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3588 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3589 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3590 | ExpectLogContainsSomewhere( |
| 3591 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3592 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3593 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3594 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3595 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3596 | ASSERT_TRUE(response); |
| 3597 | ASSERT_TRUE(response->headers); |
| 3598 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3599 | EXPECT_EQ(407, response->headers->response_code()); |
| 3600 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3601 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3602 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3603 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3604 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3605 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3606 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3607 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3608 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3609 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3610 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3611 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3612 | ASSERT_TRUE(response); |
| 3613 | ASSERT_TRUE(response->headers); |
| 3614 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3615 | EXPECT_EQ(407, response->headers->response_code()); |
| 3616 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3617 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3618 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3619 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3620 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3621 | // out of scope. |
| 3622 | session->CloseAllConnections(); |
| 3623 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3624 | } |
| 3625 | |
| 3626 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3627 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3628 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3629 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3630 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3631 | // reused. See http://crbug.com/544255. |
| 3632 | for (int i = 0; i < 2; ++i) { |
| 3633 | HttpRequestInfo request; |
| 3634 | request.method = "GET"; |
| 3635 | request.url = GURL("https://www.example.org/"); |
| 3636 | // Ensure that proxy authentication is attempted even |
| 3637 | // when the no authentication data flag is set. |
| 3638 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3639 | request.traffic_annotation = |
| 3640 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3641 | |
| 3642 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3643 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3644 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3645 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3646 | BoundTestNetLog log; |
| 3647 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3648 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3649 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3650 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3651 | |
| 3652 | // Since we have proxy, should try to establish tunnel. |
| 3653 | MockWrite data_writes1[] = { |
| 3654 | MockWrite(ASYNC, 0, |
| 3655 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3656 | "Host: www.example.org:443\r\n" |
| 3657 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3658 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3659 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3660 | // be issuing -- the final header line contains the credentials. |
| 3661 | MockWrite(ASYNC, 3, |
| 3662 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3663 | "Host: www.example.org:443\r\n" |
| 3664 | "Proxy-Connection: keep-alive\r\n" |
| 3665 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3666 | }; |
| 3667 | |
| 3668 | // The proxy responds to the connect with a 407, using a persistent |
| 3669 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3670 | MockRead data_reads1[] = { |
| 3671 | // No credentials. |
| 3672 | MockRead(ASYNC, 1, |
| 3673 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3674 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3675 | "Content-Length: 10\r\n\r\n"), |
| 3676 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3677 | |
| 3678 | // Wrong credentials (wrong password). |
| 3679 | MockRead(ASYNC, 4, |
| 3680 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3681 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3682 | "Content-Length: 10\r\n\r\n"), |
| 3683 | // No response body because the test stops reading here. |
| 3684 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3685 | }; |
| 3686 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3687 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3688 | data1.set_busy_before_sync_reads(true); |
| 3689 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3690 | |
| 3691 | TestCompletionCallback callback1; |
| 3692 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3693 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3694 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3695 | |
| 3696 | TestNetLogEntry::List entries; |
| 3697 | log.GetEntries(&entries); |
| 3698 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3699 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3700 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3701 | ExpectLogContainsSomewhere( |
| 3702 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3703 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3704 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3705 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3706 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3707 | ASSERT_TRUE(response); |
| 3708 | ASSERT_TRUE(response->headers); |
| 3709 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3710 | EXPECT_EQ(407, response->headers->response_code()); |
| 3711 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3712 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3713 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3714 | |
| 3715 | TestCompletionCallback callback2; |
| 3716 | |
| 3717 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3718 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3719 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3720 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3721 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3722 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3723 | ASSERT_TRUE(response); |
| 3724 | ASSERT_TRUE(response->headers); |
| 3725 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3726 | EXPECT_EQ(407, response->headers->response_code()); |
| 3727 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3728 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3729 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3730 | |
| 3731 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3732 | // out of scope. |
| 3733 | session->CloseAllConnections(); |
| 3734 | } |
| 3735 | } |
| 3736 | |
| 3737 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3738 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3739 | // the case the server sends extra data on the original socket, so it can't be |
| 3740 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3741 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3742 | HttpRequestInfo request; |
| 3743 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3744 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3745 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3746 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3747 | request.traffic_annotation = |
| 3748 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3749 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3750 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3751 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3752 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3753 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3754 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3755 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3756 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3757 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3758 | // Since we have proxy, should try to establish tunnel. |
| 3759 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3760 | MockWrite(ASYNC, 0, |
| 3761 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3762 | "Host: www.example.org:443\r\n" |
| 3763 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3764 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3765 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3766 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3767 | // extra data, so the socket cannot be reused. |
| 3768 | MockRead data_reads1[] = { |
| 3769 | // No credentials. |
| 3770 | MockRead(ASYNC, 1, |
| 3771 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3772 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3773 | "Content-Length: 10\r\n\r\n"), |
| 3774 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3775 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3776 | }; |
| 3777 | |
| 3778 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3779 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3780 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3781 | MockWrite(ASYNC, 0, |
| 3782 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3783 | "Host: www.example.org:443\r\n" |
| 3784 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3785 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3786 | |
| 3787 | MockWrite(ASYNC, 2, |
| 3788 | "GET / HTTP/1.1\r\n" |
| 3789 | "Host: www.example.org\r\n" |
| 3790 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3791 | }; |
| 3792 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3793 | MockRead data_reads2[] = { |
| 3794 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3795 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3796 | MockRead(ASYNC, 3, |
| 3797 | "HTTP/1.1 200 OK\r\n" |
| 3798 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3799 | "Content-Length: 5\r\n\r\n"), |
| 3800 | // No response body because the test stops reading here. |
| 3801 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3802 | }; |
| 3803 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3804 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3805 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3806 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3807 | SequencedSocketData data2(data_reads2, data_writes2); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3808 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3809 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3810 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3811 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3812 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3813 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3814 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3815 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3816 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3817 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3818 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3819 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3820 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3821 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3822 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3823 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3824 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3825 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3826 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3827 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3828 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3829 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3830 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3831 | ASSERT_TRUE(response); |
| 3832 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3833 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3834 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3835 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3836 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3837 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3838 | LoadTimingInfo load_timing_info; |
| 3839 | // CONNECT requests and responses are handled at the connect job level, so |
| 3840 | // the transaction does not yet have a connection. |
| 3841 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3842 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3843 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3844 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3845 | rv = |
| 3846 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3847 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3848 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3849 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3850 | EXPECT_EQ(200, response->headers->response_code()); |
| 3851 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3852 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3853 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3854 | // The password prompt info should not be set. |
| 3855 | EXPECT_FALSE(response->auth_challenge); |
| 3856 | |
| 3857 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3858 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3859 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3860 | |
| 3861 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3862 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3863 | } |
| 3864 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3865 | // Test the case a proxy closes a socket while the challenge body is being |
| 3866 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3867 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3868 | HttpRequestInfo request; |
| 3869 | request.method = "GET"; |
| 3870 | request.url = GURL("https://www.example.org/"); |
| 3871 | // Ensure that proxy authentication is attempted even |
| 3872 | // when the no authentication data flag is set. |
| 3873 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3874 | request.traffic_annotation = |
| 3875 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3876 | |
| 3877 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3878 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3879 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3880 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3881 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3882 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3883 | |
| 3884 | // Since we have proxy, should try to establish tunnel. |
| 3885 | MockWrite data_writes1[] = { |
| 3886 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3887 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3888 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3889 | }; |
| 3890 | |
| 3891 | // The proxy responds to the connect with a 407, using a persistent |
| 3892 | // connection. |
| 3893 | MockRead data_reads1[] = { |
| 3894 | // No credentials. |
| 3895 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3896 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3897 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3898 | // Server hands up in the middle of the body. |
| 3899 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3900 | }; |
| 3901 | |
| 3902 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3903 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3904 | // be issuing -- the final header line contains the credentials. |
| 3905 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3906 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3907 | "Proxy-Connection: keep-alive\r\n" |
| 3908 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3909 | |
| 3910 | MockWrite("GET / HTTP/1.1\r\n" |
| 3911 | "Host: www.example.org\r\n" |
| 3912 | "Connection: keep-alive\r\n\r\n"), |
| 3913 | }; |
| 3914 | |
| 3915 | MockRead data_reads2[] = { |
| 3916 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3917 | |
| 3918 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3919 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3920 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3921 | MockRead(SYNCHRONOUS, "hello"), |
| 3922 | }; |
| 3923 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3924 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3925 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3926 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3927 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3928 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3929 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3930 | |
| 3931 | TestCompletionCallback callback; |
| 3932 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3933 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3934 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3935 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3936 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3937 | ASSERT_TRUE(response); |
| 3938 | ASSERT_TRUE(response->headers); |
| 3939 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3940 | EXPECT_EQ(407, response->headers->response_code()); |
| 3941 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3942 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3943 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3944 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3945 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3946 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3947 | ASSERT_TRUE(response); |
| 3948 | ASSERT_TRUE(response->headers); |
| 3949 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3950 | EXPECT_EQ(200, response->headers->response_code()); |
| 3951 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3952 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3953 | EXPECT_EQ("hello", body); |
| 3954 | } |
| 3955 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3956 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3957 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3958 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3959 | HttpRequestInfo request; |
| 3960 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3961 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3962 | request.traffic_annotation = |
| 3963 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3964 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3965 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3966 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3967 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3968 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3969 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3970 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3971 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3972 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3973 | // Since we have proxy, should try to establish tunnel. |
| 3974 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3975 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3976 | "Host: www.example.org:443\r\n" |
| 3977 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3978 | }; |
| 3979 | |
| 3980 | // The proxy responds to the connect with a 407. |
| 3981 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3982 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3983 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3984 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3985 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3986 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3987 | }; |
| 3988 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3989 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3990 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3991 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3992 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3993 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3994 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3995 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3996 | |
| 3997 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3998 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3999 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4000 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4001 | ASSERT_TRUE(response); |
| 4002 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4003 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4004 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4005 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4006 | |
| 4007 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4008 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4009 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 4010 | |
| 4011 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 4012 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4013 | } |
| 4014 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4015 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 4016 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4017 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4018 | HttpRequestInfo request; |
| 4019 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4020 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4021 | request.traffic_annotation = |
| 4022 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4023 | |
| 4024 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4025 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4026 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4027 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4028 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4029 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4030 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4031 | |
| 4032 | // Since we have proxy, should try to establish tunnel. |
| 4033 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4034 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4035 | "Host: www.example.org:443\r\n" |
| 4036 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4037 | }; |
| 4038 | |
| 4039 | // The proxy responds to the connect with a 407. |
| 4040 | MockRead data_reads[] = { |
| 4041 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4042 | MockRead("X-Foo: bar\r\n"), |
| 4043 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 4044 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4045 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4046 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4047 | }; |
| 4048 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4049 | StaticSocketDataProvider data(data_reads, data_writes); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4050 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4051 | |
| 4052 | TestCompletionCallback callback; |
| 4053 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4054 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4055 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4056 | |
| 4057 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4058 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4059 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4060 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4061 | ASSERT_TRUE(response); |
| 4062 | ASSERT_TRUE(response->headers); |
| 4063 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4064 | EXPECT_EQ(407, response->headers->response_code()); |
| 4065 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4066 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 4067 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 4068 | |
| 4069 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4070 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4071 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4072 | |
| 4073 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 4074 | session->CloseAllConnections(); |
| 4075 | } |
| 4076 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4077 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 4078 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4079 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4080 | HttpRequestInfo request; |
| 4081 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4082 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4083 | request.traffic_annotation = |
| 4084 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4085 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4086 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4087 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4088 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4089 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4090 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4091 | MockWrite( |
| 4092 | "GET / HTTP/1.1\r\n" |
| 4093 | "Host: www.example.org\r\n" |
| 4094 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4095 | }; |
| 4096 | |
| 4097 | MockRead data_reads1[] = { |
| 4098 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 4099 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4100 | // Large content-length -- won't matter, as connection will be reset. |
| 4101 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4102 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4103 | }; |
| 4104 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4105 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4106 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4107 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4108 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4109 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4110 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4111 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4112 | |
| 4113 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4114 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4115 | } |
| 4116 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4117 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 4118 | // through a non-authenticating proxy. The request should fail with |
| 4119 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 4120 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 4121 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 4122 | // response came from the proxy or the server, so it is treated as if the proxy |
| 4123 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4124 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4125 | HttpRequestInfo request; |
| 4126 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4127 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4128 | request.traffic_annotation = |
| 4129 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4130 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4131 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4132 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4133 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4134 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4135 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4136 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4137 | // Since we have proxy, should try to establish tunnel. |
| 4138 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4139 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4140 | "Host: www.example.org:443\r\n" |
| 4141 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4142 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4143 | MockWrite("GET / HTTP/1.1\r\n" |
| 4144 | "Host: www.example.org\r\n" |
| 4145 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4146 | }; |
| 4147 | |
| 4148 | MockRead data_reads1[] = { |
| 4149 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4150 | |
| 4151 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 4152 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4153 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4154 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4155 | }; |
| 4156 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4157 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4158 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4159 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4160 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4161 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4162 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4163 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4164 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4165 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4166 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4167 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4168 | |
| 4169 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4170 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 4171 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4172 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4173 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4174 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 4175 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4176 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4177 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4178 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 4179 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4180 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4181 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4182 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4183 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4184 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4185 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 4186 | HttpRequestInfo request; |
| 4187 | request.method = "GET"; |
| 4188 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4189 | request.traffic_annotation = |
| 4190 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4191 | |
| 4192 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4193 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4194 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4195 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4196 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4197 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4198 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4199 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4200 | mock_handler->set_allows_default_credentials(true); |
| 4201 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4202 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4203 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4204 | |
| 4205 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4206 | NetLog net_log; |
| 4207 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4208 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4209 | |
| 4210 | // Since we have proxy, should try to establish tunnel. |
| 4211 | MockWrite data_writes1[] = { |
| 4212 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4213 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4214 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4215 | }; |
| 4216 | |
| 4217 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4218 | // connection. |
| 4219 | MockRead data_reads1[] = { |
| 4220 | // No credentials. |
| 4221 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4222 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4223 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4224 | }; |
| 4225 | |
| 4226 | // Since the first connection couldn't be reused, need to establish another |
| 4227 | // once given credentials. |
| 4228 | MockWrite data_writes2[] = { |
| 4229 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4230 | // be issuing -- the final header line contains the credentials. |
| 4231 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4232 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4233 | "Proxy-Connection: keep-alive\r\n" |
| 4234 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4235 | |
| 4236 | MockWrite("GET / HTTP/1.1\r\n" |
| 4237 | "Host: www.example.org\r\n" |
| 4238 | "Connection: keep-alive\r\n\r\n"), |
| 4239 | }; |
| 4240 | |
| 4241 | MockRead data_reads2[] = { |
| 4242 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4243 | |
| 4244 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4245 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4246 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4247 | MockRead(SYNCHRONOUS, "hello"), |
| 4248 | }; |
| 4249 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4250 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4251 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4252 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4253 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4254 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4255 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4256 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4257 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4258 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4259 | |
| 4260 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4261 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4262 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4263 | |
| 4264 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4265 | ASSERT_TRUE(response); |
| 4266 | ASSERT_TRUE(response->headers); |
| 4267 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4268 | EXPECT_EQ(407, response->headers->response_code()); |
| 4269 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4270 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4271 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4272 | |
| 4273 | LoadTimingInfo load_timing_info; |
| 4274 | // CONNECT requests and responses are handled at the connect job level, so |
| 4275 | // the transaction does not yet have a connection. |
| 4276 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4277 | |
| 4278 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4279 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4280 | response = trans->GetResponseInfo(); |
| 4281 | ASSERT_TRUE(response); |
| 4282 | ASSERT_TRUE(response->headers); |
| 4283 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4284 | EXPECT_EQ(200, response->headers->response_code()); |
| 4285 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4286 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4287 | |
| 4288 | // The password prompt info should not be set. |
| 4289 | EXPECT_FALSE(response->auth_challenge); |
| 4290 | |
| 4291 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4292 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4293 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4294 | |
| 4295 | trans.reset(); |
| 4296 | session->CloseAllConnections(); |
| 4297 | } |
| 4298 | |
| 4299 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4300 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4301 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4302 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4303 | HttpRequestInfo request; |
| 4304 | request.method = "GET"; |
| 4305 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4306 | request.traffic_annotation = |
| 4307 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4308 | |
| 4309 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4310 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4311 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4312 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4313 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4314 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4315 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4316 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4317 | mock_handler->set_allows_default_credentials(true); |
| 4318 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4319 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4320 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4321 | |
| 4322 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4323 | NetLog net_log; |
| 4324 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4325 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4326 | |
| 4327 | // Should try to establish tunnel. |
| 4328 | MockWrite data_writes1[] = { |
| 4329 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4330 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4331 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4332 | |
| 4333 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4334 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4335 | "Proxy-Connection: keep-alive\r\n" |
| 4336 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4337 | }; |
| 4338 | |
| 4339 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4340 | // connection. |
| 4341 | MockRead data_reads1[] = { |
| 4342 | // No credentials. |
| 4343 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4344 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4345 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4346 | }; |
| 4347 | |
| 4348 | // Since the first connection was closed, need to establish another once given |
| 4349 | // credentials. |
| 4350 | MockWrite data_writes2[] = { |
| 4351 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4352 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4353 | "Proxy-Connection: keep-alive\r\n" |
| 4354 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4355 | |
| 4356 | MockWrite("GET / HTTP/1.1\r\n" |
| 4357 | "Host: www.example.org\r\n" |
| 4358 | "Connection: keep-alive\r\n\r\n"), |
| 4359 | }; |
| 4360 | |
| 4361 | MockRead data_reads2[] = { |
| 4362 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4363 | |
| 4364 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4365 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4366 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4367 | MockRead(SYNCHRONOUS, "hello"), |
| 4368 | }; |
| 4369 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4370 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4371 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4372 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4373 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4374 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4375 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4376 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4377 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4378 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4379 | |
| 4380 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4381 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4382 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4383 | |
| 4384 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4385 | ASSERT_TRUE(response); |
| 4386 | ASSERT_TRUE(response->headers); |
| 4387 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4388 | EXPECT_EQ(407, response->headers->response_code()); |
| 4389 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4390 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4391 | EXPECT_FALSE(response->auth_challenge); |
| 4392 | |
| 4393 | LoadTimingInfo load_timing_info; |
| 4394 | // CONNECT requests and responses are handled at the connect job level, so |
| 4395 | // the transaction does not yet have a connection. |
| 4396 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4397 | |
| 4398 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4399 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4400 | |
| 4401 | response = trans->GetResponseInfo(); |
| 4402 | ASSERT_TRUE(response); |
| 4403 | ASSERT_TRUE(response->headers); |
| 4404 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4405 | EXPECT_EQ(200, response->headers->response_code()); |
| 4406 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4407 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4408 | |
| 4409 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4410 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4411 | |
| 4412 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4413 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4414 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4415 | |
| 4416 | trans.reset(); |
| 4417 | session->CloseAllConnections(); |
| 4418 | } |
| 4419 | |
| 4420 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4421 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4422 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4423 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4424 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4425 | HttpRequestInfo request; |
| 4426 | request.method = "GET"; |
| 4427 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4428 | request.traffic_annotation = |
| 4429 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4430 | |
| 4431 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4432 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4433 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4434 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4435 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4436 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4437 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4438 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4439 | mock_handler->set_allows_default_credentials(true); |
| 4440 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4441 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4442 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4443 | |
| 4444 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4445 | NetLog net_log; |
| 4446 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4447 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4448 | |
| 4449 | // Should try to establish tunnel. |
| 4450 | MockWrite data_writes1[] = { |
| 4451 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4452 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4453 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4454 | |
| 4455 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4456 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4457 | "Proxy-Connection: keep-alive\r\n" |
| 4458 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4459 | }; |
| 4460 | |
| 4461 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4462 | // second request is sent. |
| 4463 | MockRead data_reads1[] = { |
| 4464 | // No credentials. |
| 4465 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4466 | MockRead("Content-Length: 0\r\n"), |
| 4467 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4468 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4469 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4470 | }; |
| 4471 | |
| 4472 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4473 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4474 | // request. |
| 4475 | MockWrite data_writes2[] = { |
| 4476 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4477 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4478 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4479 | }; |
| 4480 | |
| 4481 | // The proxy, having had more than enough of us, just hangs up. |
| 4482 | MockRead data_reads2[] = { |
| 4483 | // No credentials. |
| 4484 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4485 | }; |
| 4486 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4487 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4488 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4489 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4490 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4491 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4492 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4493 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4494 | |
| 4495 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4496 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4497 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4498 | |
| 4499 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4500 | ASSERT_TRUE(response); |
| 4501 | ASSERT_TRUE(response->headers); |
| 4502 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4503 | EXPECT_EQ(407, response->headers->response_code()); |
| 4504 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4505 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4506 | EXPECT_FALSE(response->auth_challenge); |
| 4507 | |
| 4508 | LoadTimingInfo load_timing_info; |
| 4509 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4510 | |
| 4511 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4512 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4513 | |
| 4514 | trans.reset(); |
| 4515 | session->CloseAllConnections(); |
| 4516 | } |
| 4517 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4518 | // This test exercises an odd edge case where the proxy closes the connection |
| 4519 | // after the authentication handshake is complete. Presumably this technique is |
| 4520 | // used in lieu of returning a 403 or 5xx status code when the authentication |
| 4521 | // succeeds, but the user is not authorized to connect to the destination |
| 4522 | // server. There's no standard for what a proxy should do to indicate a blocked |
| 4523 | // site. |
| 4524 | TEST_F(HttpNetworkTransactionTest, |
| 4525 | AuthAllowsDefaultCredentialsTunnelConnectionClosesBeforeBody) { |
| 4526 | HttpRequestInfo request; |
| 4527 | request.method = "GET"; |
| 4528 | request.url = GURL("https://www.example.org/"); |
| 4529 | request.traffic_annotation = |
| 4530 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4531 | |
| 4532 | // Configure against proxy server "myproxy:70". |
| 4533 | session_deps_.proxy_resolution_service = |
| 4534 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4535 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4536 | |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 4537 | // When TLS 1.3 is enabled, spurious connections are made as part of the SSL |
| 4538 | // version interference probes. |
| 4539 | // TODO(crbug.com/906668): Correctly handle version interference probes to |
| 4540 | // test TLS 1.3. |
| 4541 | SSLConfig config; |
| 4542 | config.version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
| 4543 | session_deps_.ssl_config_service = |
| 4544 | std::make_unique<TestSSLConfigService>(config); |
| 4545 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4546 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
| 4547 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4548 | |
| 4549 | // Create two mock AuthHandlers. This is because the transaction gets retried |
| 4550 | // after the first ERR_CONNECTION_CLOSED since it's ambiguous whether there |
| 4551 | // was a real network error. |
| 4552 | // |
| 4553 | // The handlers support both default and explicit credentials. The retry |
| 4554 | // mentioned above should be able to reuse the default identity. Thus there |
| 4555 | // should never be a need to prompt for explicit credentials. |
| 4556 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4557 | mock_handler->set_allows_default_credentials(true); |
| 4558 | mock_handler->set_allows_explicit_credentials(true); |
| 4559 | mock_handler->set_connection_based(true); |
| 4560 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4561 | HttpAuth::AUTH_PROXY); |
| 4562 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4563 | mock_handler->set_allows_default_credentials(true); |
| 4564 | mock_handler->set_allows_explicit_credentials(true); |
| 4565 | mock_handler->set_connection_based(true); |
| 4566 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4567 | HttpAuth::AUTH_PROXY); |
| 4568 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4569 | |
| 4570 | NetLog net_log; |
| 4571 | session_deps_.net_log = &net_log; |
| 4572 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4573 | |
| 4574 | // Data for both sockets. |
| 4575 | // |
| 4576 | // Writes are for the tunnel establishment attempts and the |
| 4577 | // authentication handshake. |
| 4578 | MockWrite data_writes1[] = { |
| 4579 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4580 | "Host: www.example.org:443\r\n" |
| 4581 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4582 | |
| 4583 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4584 | "Host: www.example.org:443\r\n" |
| 4585 | "Proxy-Connection: keep-alive\r\n" |
| 4586 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4587 | |
| 4588 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4589 | "Host: www.example.org:443\r\n" |
| 4590 | "Proxy-Connection: keep-alive\r\n" |
| 4591 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4592 | }; |
| 4593 | |
| 4594 | // The server side of the authentication handshake. Note that the response to |
| 4595 | // the final CONNECT request is ERR_CONNECTION_CLOSED. |
| 4596 | MockRead data_reads1[] = { |
| 4597 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4598 | MockRead("Content-Length: 0\r\n"), |
| 4599 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4600 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4601 | |
| 4602 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4603 | MockRead("Content-Length: 0\r\n"), |
| 4604 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4605 | MockRead("Proxy-Authenticate: Mock foo\r\n\r\n"), |
| 4606 | |
| 4607 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4608 | }; |
| 4609 | |
| 4610 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 4611 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4612 | |
| 4613 | // The second socket is for the reconnection attempt. Data is identical to the |
| 4614 | // first attempt. |
| 4615 | StaticSocketDataProvider data2(data_reads1, data_writes1); |
| 4616 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4617 | |
| 4618 | auto trans = |
| 4619 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4620 | |
| 4621 | TestCompletionCallback callback; |
| 4622 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4623 | |
| 4624 | // Two rounds per handshake. After one retry, the error is propagated up the |
| 4625 | // stack. |
| 4626 | for (int i = 0; i < 4; ++i) { |
| 4627 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4628 | |
| 4629 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4630 | ASSERT_TRUE(response); |
| 4631 | ASSERT_TRUE(response->headers); |
| 4632 | EXPECT_EQ(407, response->headers->response_code()); |
| 4633 | ASSERT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4634 | |
| 4635 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4636 | } |
| 4637 | |
| 4638 | // One shall be the number thou shalt retry, and the number of the retrying |
| 4639 | // shall be one. Two shalt thou not retry, neither retry thou zero, excepting |
| 4640 | // that thou then proceed to one. Three is right out. Once the number one, |
| 4641 | // being the first number, be reached, then lobbest thou thy |
| 4642 | // ERR_CONNECTION_CLOSED towards they network transaction, who shall snuff it. |
| 4643 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.GetResult(rv)); |
| 4644 | |
| 4645 | trans.reset(); |
| 4646 | session->CloseAllConnections(); |
| 4647 | } |
| 4648 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4649 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4650 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4651 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4652 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4653 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4654 | HttpRequestInfo request; |
| 4655 | request.method = "GET"; |
| 4656 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4657 | request.traffic_annotation = |
| 4658 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4659 | |
| 4660 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4661 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4662 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4663 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4664 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4665 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4666 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4667 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4668 | mock_handler->set_allows_default_credentials(true); |
| 4669 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4670 | HttpAuth::AUTH_PROXY); |
| 4671 | // Add another handler for the second challenge. It supports default |
| 4672 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4673 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4674 | mock_handler->set_allows_default_credentials(true); |
| 4675 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4676 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4677 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4678 | |
| 4679 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4680 | NetLog net_log; |
| 4681 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4682 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4683 | |
| 4684 | // Should try to establish tunnel. |
| 4685 | MockWrite data_writes1[] = { |
| 4686 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4687 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4688 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4689 | }; |
| 4690 | |
| 4691 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4692 | // connection. |
| 4693 | MockRead data_reads1[] = { |
| 4694 | // No credentials. |
| 4695 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4696 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4697 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4698 | }; |
| 4699 | |
| 4700 | // Since the first connection was closed, need to establish another once given |
| 4701 | // credentials. |
| 4702 | MockWrite data_writes2[] = { |
| 4703 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4704 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4705 | "Proxy-Connection: keep-alive\r\n" |
| 4706 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4707 | }; |
| 4708 | |
| 4709 | MockRead data_reads2[] = { |
| 4710 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4711 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4712 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4713 | }; |
| 4714 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4715 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4716 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4717 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4718 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4719 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4720 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4721 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4722 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4723 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4724 | |
| 4725 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4726 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4727 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4728 | |
| 4729 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4730 | ASSERT_TRUE(response); |
| 4731 | ASSERT_TRUE(response->headers); |
| 4732 | EXPECT_EQ(407, response->headers->response_code()); |
| 4733 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4734 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4735 | EXPECT_FALSE(response->auth_challenge); |
| 4736 | |
| 4737 | LoadTimingInfo load_timing_info; |
| 4738 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4739 | |
| 4740 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4741 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4742 | response = trans->GetResponseInfo(); |
| 4743 | ASSERT_TRUE(response); |
| 4744 | ASSERT_TRUE(response->headers); |
| 4745 | EXPECT_EQ(407, response->headers->response_code()); |
| 4746 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4747 | EXPECT_TRUE(response->auth_challenge); |
| 4748 | |
| 4749 | trans.reset(); |
| 4750 | session->CloseAllConnections(); |
| 4751 | } |
| 4752 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4753 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4754 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4755 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4756 | // authentication handshake can continue with the same scheme but with a |
| 4757 | // different identity. |
| 4758 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4759 | HttpRequestInfo request; |
| 4760 | request.method = "GET"; |
| 4761 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4762 | request.traffic_annotation = |
| 4763 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4764 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4765 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4766 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4767 | |
| 4768 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4769 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4770 | mock_handler->set_allows_default_credentials(true); |
| 4771 | mock_handler->set_allows_explicit_credentials(true); |
| 4772 | mock_handler->set_connection_based(true); |
| 4773 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4774 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4775 | HttpAuth::AUTH_SERVER); |
| 4776 | |
| 4777 | // Add another handler for the second challenge. It supports default |
| 4778 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4779 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4780 | mock_handler->set_allows_default_credentials(true); |
| 4781 | mock_handler->set_allows_explicit_credentials(true); |
| 4782 | mock_handler->set_connection_based(true); |
| 4783 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4784 | HttpAuth::AUTH_SERVER); |
| 4785 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4786 | |
| 4787 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4788 | |
| 4789 | MockWrite data_writes1[] = { |
| 4790 | MockWrite("GET / HTTP/1.1\r\n" |
| 4791 | "Host: www.example.org\r\n" |
| 4792 | "Connection: keep-alive\r\n\r\n"), |
| 4793 | }; |
| 4794 | |
| 4795 | MockRead data_reads1[] = { |
| 4796 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4797 | "WWW-Authenticate: Mock\r\n" |
| 4798 | "Connection: keep-alive\r\n\r\n"), |
| 4799 | }; |
| 4800 | |
| 4801 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4802 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4803 | // transaction procceds without an authorization header. |
| 4804 | MockWrite data_writes2[] = { |
| 4805 | MockWrite("GET / HTTP/1.1\r\n" |
| 4806 | "Host: www.example.org\r\n" |
| 4807 | "Connection: keep-alive\r\n\r\n"), |
| 4808 | }; |
| 4809 | |
| 4810 | MockRead data_reads2[] = { |
| 4811 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4812 | "WWW-Authenticate: Mock\r\n" |
| 4813 | "Connection: keep-alive\r\n\r\n"), |
| 4814 | }; |
| 4815 | |
| 4816 | MockWrite data_writes3[] = { |
| 4817 | MockWrite("GET / HTTP/1.1\r\n" |
| 4818 | "Host: www.example.org\r\n" |
| 4819 | "Connection: keep-alive\r\n" |
| 4820 | "Authorization: auth_token\r\n\r\n"), |
| 4821 | }; |
| 4822 | |
| 4823 | MockRead data_reads3[] = { |
| 4824 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4825 | "Content-Length: 5\r\n" |
| 4826 | "Content-Type: text/plain\r\n" |
| 4827 | "Connection: keep-alive\r\n\r\n" |
| 4828 | "Hello"), |
| 4829 | }; |
| 4830 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4831 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4832 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4833 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4834 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4835 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4836 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4837 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4838 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4839 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4840 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4841 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4842 | |
| 4843 | TestCompletionCallback callback; |
| 4844 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4845 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4846 | |
| 4847 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4848 | ASSERT_TRUE(response); |
| 4849 | ASSERT_TRUE(response->headers); |
| 4850 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4851 | |
| 4852 | // The following three tests assert that an authentication challenge was |
| 4853 | // received and that the stack is ready to respond to the challenge using |
| 4854 | // ambient credentials. |
| 4855 | EXPECT_EQ(401, response->headers->response_code()); |
| 4856 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4857 | EXPECT_FALSE(response->auth_challenge); |
| 4858 | |
| 4859 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4860 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4861 | response = trans->GetResponseInfo(); |
| 4862 | ASSERT_TRUE(response); |
| 4863 | ASSERT_TRUE(response->headers); |
| 4864 | |
| 4865 | // The following three tests assert that an authentication challenge was |
| 4866 | // received and that the stack needs explicit credentials before it is ready |
| 4867 | // to respond to the challenge. |
| 4868 | EXPECT_EQ(401, response->headers->response_code()); |
| 4869 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4870 | EXPECT_TRUE(response->auth_challenge); |
| 4871 | |
| 4872 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4873 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4874 | response = trans->GetResponseInfo(); |
| 4875 | ASSERT_TRUE(response); |
| 4876 | ASSERT_TRUE(response->headers); |
| 4877 | EXPECT_EQ(200, response->headers->response_code()); |
| 4878 | |
| 4879 | trans.reset(); |
| 4880 | session->CloseAllConnections(); |
| 4881 | } |
| 4882 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4883 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4884 | // schemes, based on the path of the URL being requests. |
| 4885 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4886 | public: |
| 4887 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4888 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4889 | |
| 4890 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4891 | |
| 4892 | static HostPortPair ProxyHostPortPair() { |
| 4893 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4894 | } |
| 4895 | |
| 4896 | // ProxyResolver implementation. |
| 4897 | int GetProxyForURL(const GURL& url, |
| 4898 | ProxyInfo* results, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4899 | CompletionOnceCallback callback, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4900 | std::unique_ptr<Request>* request, |
| 4901 | const NetLogWithSource& /*net_log*/) override { |
| 4902 | *results = ProxyInfo(); |
Ramin Halavati | 921731ea | 2018-03-16 08:24:57 | [diff] [blame] | 4903 | results->set_traffic_annotation( |
| 4904 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4905 | if (url.path() == "/socks4") { |
| 4906 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 4907 | return OK; |
| 4908 | } |
| 4909 | if (url.path() == "/socks5") { |
| 4910 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 4911 | return OK; |
| 4912 | } |
| 4913 | if (url.path() == "/http") { |
| 4914 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 4915 | return OK; |
| 4916 | } |
| 4917 | if (url.path() == "/https") { |
| 4918 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 4919 | return OK; |
| 4920 | } |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 4921 | if (url.path() == "/https_trusted") { |
| 4922 | results->UseProxyServer(ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 4923 | ProxyHostPortPair(), |
| 4924 | true /* is_trusted_proxy */)); |
| 4925 | return OK; |
| 4926 | } |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4927 | NOTREACHED(); |
| 4928 | return ERR_NOT_IMPLEMENTED; |
| 4929 | } |
| 4930 | |
| 4931 | private: |
| 4932 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 4933 | }; |
| 4934 | |
| 4935 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 4936 | : public ProxyResolverFactory { |
| 4937 | public: |
| 4938 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 4939 | : ProxyResolverFactory(false) {} |
| 4940 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4941 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 4942 | std::unique_ptr<ProxyResolver>* resolver, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4943 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4944 | std::unique_ptr<Request>* request) override { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4945 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 4946 | return OK; |
| 4947 | } |
| 4948 | |
| 4949 | private: |
| 4950 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 4951 | }; |
| 4952 | |
| 4953 | // 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] | 4954 | // same address, the connections are not grouped together. i.e., a request to |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4955 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 4956 | // request to foo.com using proxy.com as an HTTP proxy. |
| 4957 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4958 | session_deps_.proxy_resolution_service = |
| 4959 | std::make_unique<ProxyResolutionService>( |
| 4960 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 4961 | ProxyConfig::CreateAutoDetect(), TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 4962 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 4963 | nullptr); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4964 | |
| 4965 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4966 | |
| 4967 | MockWrite socks_writes[] = { |
| 4968 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 4969 | kSOCKS4OkRequestLocalHostPort80Length), |
| 4970 | MockWrite(SYNCHRONOUS, |
| 4971 | "GET /socks4 HTTP/1.1\r\n" |
| 4972 | "Host: test\r\n" |
| 4973 | "Connection: keep-alive\r\n\r\n"), |
| 4974 | }; |
| 4975 | MockRead socks_reads[] = { |
| 4976 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 4977 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4978 | "Connection: keep-alive\r\n" |
| 4979 | "Content-Length: 15\r\n\r\n" |
| 4980 | "SOCKS4 Response"), |
| 4981 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4982 | StaticSocketDataProvider socks_data(socks_reads, socks_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4983 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 4984 | |
| 4985 | const char kSOCKS5Request[] = { |
| 4986 | 0x05, // Version |
| 4987 | 0x01, // Command (CONNECT) |
| 4988 | 0x00, // Reserved |
| 4989 | 0x03, // Address type (DOMAINNAME) |
| 4990 | 0x04, // Length of domain (4) |
| 4991 | 't', 'e', 's', 't', // Domain string |
| 4992 | 0x00, 0x50, // 16-bit port (80) |
| 4993 | }; |
| 4994 | MockWrite socks5_writes[] = { |
| 4995 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 4996 | MockWrite(ASYNC, kSOCKS5Request, base::size(kSOCKS5Request)), |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4997 | MockWrite(SYNCHRONOUS, |
| 4998 | "GET /socks5 HTTP/1.1\r\n" |
| 4999 | "Host: test\r\n" |
| 5000 | "Connection: keep-alive\r\n\r\n"), |
| 5001 | }; |
| 5002 | MockRead socks5_reads[] = { |
| 5003 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 5004 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 5005 | MockRead("HTTP/1.0 200 OK\r\n" |
| 5006 | "Connection: keep-alive\r\n" |
| 5007 | "Content-Length: 15\r\n\r\n" |
| 5008 | "SOCKS5 Response"), |
| 5009 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5010 | StaticSocketDataProvider socks5_data(socks5_reads, socks5_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5011 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 5012 | |
| 5013 | MockWrite http_writes[] = { |
| 5014 | MockWrite(SYNCHRONOUS, |
| 5015 | "GET http://test/http HTTP/1.1\r\n" |
| 5016 | "Host: test\r\n" |
| 5017 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5018 | }; |
| 5019 | MockRead http_reads[] = { |
| 5020 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5021 | "Proxy-Connection: keep-alive\r\n" |
| 5022 | "Content-Length: 13\r\n\r\n" |
| 5023 | "HTTP Response"), |
| 5024 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5025 | StaticSocketDataProvider http_data(http_reads, http_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5026 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 5027 | |
| 5028 | MockWrite https_writes[] = { |
| 5029 | MockWrite(SYNCHRONOUS, |
| 5030 | "GET http://test/https HTTP/1.1\r\n" |
| 5031 | "Host: test\r\n" |
| 5032 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5033 | }; |
| 5034 | MockRead https_reads[] = { |
| 5035 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5036 | "Proxy-Connection: keep-alive\r\n" |
| 5037 | "Content-Length: 14\r\n\r\n" |
| 5038 | "HTTPS Response"), |
| 5039 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5040 | StaticSocketDataProvider https_data(https_reads, https_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5041 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 5042 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 5043 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5044 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5045 | MockWrite https_trusted_writes[] = { |
| 5046 | MockWrite(SYNCHRONOUS, |
| 5047 | "GET http://test/https_trusted HTTP/1.1\r\n" |
| 5048 | "Host: test\r\n" |
| 5049 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5050 | }; |
| 5051 | MockRead https_trusted_reads[] = { |
| 5052 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5053 | "Proxy-Connection: keep-alive\r\n" |
| 5054 | "Content-Length: 22\r\n\r\n" |
| 5055 | "HTTPS Trusted Response"), |
| 5056 | }; |
| 5057 | StaticSocketDataProvider trusted_https_data(https_trusted_reads, |
| 5058 | https_trusted_writes); |
| 5059 | session_deps_.socket_factory->AddSocketDataProvider(&trusted_https_data); |
| 5060 | SSLSocketDataProvider ssl2(SYNCHRONOUS, OK); |
| 5061 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 5062 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5063 | struct TestCase { |
| 5064 | GURL url; |
| 5065 | std::string expected_response; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5066 | // 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] | 5067 | // after the test. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5068 | int expected_idle_socks4_sockets; |
| 5069 | int expected_idle_socks5_sockets; |
| 5070 | // How many idle sockets there should be in the HTTP/HTTPS proxy socket |
| 5071 | // pools after the test. |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5072 | int expected_idle_http_sockets; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5073 | int expected_idle_https_sockets; |
| 5074 | // How many idle sockets there should be in the HTTPS proxy socket pool with |
| 5075 | // the ProxyServer's |is_trusted_proxy| bit set after the test. |
| 5076 | int expected_idle_trusted_https_sockets; |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5077 | } const kTestCases[] = { |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5078 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0, 0, 0, 0}, |
| 5079 | {GURL("http://test/socks5"), "SOCKS5 Response", 1, 1, 0, 0, 0}, |
| 5080 | {GURL("http://test/http"), "HTTP Response", 1, 1, 1, 0, 0}, |
| 5081 | {GURL("http://test/https"), "HTTPS Response", 1, 1, 1, 1, 0}, |
| 5082 | {GURL("http://test/https_trusted"), "HTTPS Trusted Response", 1, 1, 1, 1, |
| 5083 | 1}, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5084 | }; |
| 5085 | |
| 5086 | for (const auto& test_case : kTestCases) { |
| 5087 | HttpRequestInfo request; |
| 5088 | request.method = "GET"; |
| 5089 | request.url = test_case.url; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5090 | request.traffic_annotation = |
| 5091 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5092 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 5093 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 5094 | session.get()); |
| 5095 | TestCompletionCallback callback; |
| 5096 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 5097 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5098 | |
| 5099 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5100 | ASSERT_TRUE(response); |
| 5101 | ASSERT_TRUE(response->headers); |
| 5102 | EXPECT_EQ(200, response->headers->response_code()); |
| 5103 | std::string response_data; |
| 5104 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 5105 | EXPECT_EQ(test_case.expected_response, response_data); |
| 5106 | |
| 5107 | // Return the socket to the socket pool, so can make sure it's not used for |
| 5108 | // the next requests. |
| 5109 | trans.reset(); |
| 5110 | base::RunLoop().RunUntilIdle(); |
| 5111 | |
| 5112 | // Check the number of idle sockets in the pool, to make sure that used |
| 5113 | // sockets are indeed being returned to the socket pool. If each request |
| 5114 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 5115 | // pass. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5116 | EXPECT_EQ(test_case.expected_idle_socks4_sockets, |
| 5117 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5118 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5119 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5120 | ProxyServer(ProxyServer::SCHEME_SOCKS4, |
| 5121 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5122 | ProxyHostPortPair())) |
| 5123 | ->IdleSocketCount()); |
| 5124 | EXPECT_EQ(test_case.expected_idle_socks5_sockets, |
| 5125 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5126 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5127 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5128 | ProxyServer(ProxyServer::SCHEME_SOCKS5, |
| 5129 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5130 | ProxyHostPortPair())) |
| 5131 | ->IdleSocketCount()); |
| 5132 | EXPECT_EQ(test_case.expected_idle_http_sockets, |
| 5133 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5134 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5135 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5136 | ProxyServer(ProxyServer::SCHEME_HTTP, |
| 5137 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5138 | ProxyHostPortPair())) |
| 5139 | ->IdleSocketCount()); |
| 5140 | EXPECT_EQ(test_case.expected_idle_https_sockets, |
| 5141 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5142 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5143 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5144 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5145 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5146 | ProxyHostPortPair())) |
| 5147 | ->IdleSocketCount()); |
| 5148 | EXPECT_EQ(test_case.expected_idle_trusted_https_sockets, |
| 5149 | session |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 5150 | ->GetSocketPool( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5151 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5152 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5153 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5154 | ProxyHostPortPair(), |
| 5155 | true /* is_trusted_proxy */)) |
| 5156 | ->IdleSocketCount()); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5157 | } |
| 5158 | } |
| 5159 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5160 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5161 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5162 | HttpRequestInfo request1; |
| 5163 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5164 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5165 | request1.traffic_annotation = |
| 5166 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5167 | |
| 5168 | HttpRequestInfo request2; |
| 5169 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5170 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5171 | request2.traffic_annotation = |
| 5172 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5173 | |
| 5174 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5175 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5176 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5177 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5178 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5179 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5180 | |
| 5181 | // Since we have proxy, should try to establish tunnel. |
| 5182 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5183 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5184 | "Host: www.example.org:443\r\n" |
| 5185 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5186 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5187 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5188 | "Host: www.example.org\r\n" |
| 5189 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5190 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5191 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5192 | "Host: www.example.org\r\n" |
| 5193 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5194 | }; |
| 5195 | |
| 5196 | // The proxy responds to the connect with a 407, using a persistent |
| 5197 | // connection. |
| 5198 | MockRead data_reads1[] = { |
| 5199 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5200 | |
| 5201 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5202 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5203 | MockRead(SYNCHRONOUS, "1"), |
| 5204 | |
| 5205 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5206 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5207 | MockRead(SYNCHRONOUS, "22"), |
| 5208 | }; |
| 5209 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5210 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5211 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5212 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5213 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5214 | |
| 5215 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5216 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5217 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5218 | |
| 5219 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5220 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5221 | |
| 5222 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5223 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5224 | |
| 5225 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5226 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5227 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5228 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5229 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5230 | |
| 5231 | LoadTimingInfo load_timing_info1; |
| 5232 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5233 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5234 | |
| 5235 | trans1.reset(); |
| 5236 | |
| 5237 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5238 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5239 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5240 | |
| 5241 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5242 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5243 | |
| 5244 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5245 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5246 | |
| 5247 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5248 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5249 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5250 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5251 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5252 | |
| 5253 | LoadTimingInfo load_timing_info2; |
| 5254 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5255 | TestLoadTimingReused(load_timing_info2); |
| 5256 | |
| 5257 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5258 | |
| 5259 | trans2.reset(); |
| 5260 | session->CloseAllConnections(); |
| 5261 | } |
| 5262 | |
| 5263 | // 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] | 5264 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5265 | HttpRequestInfo request1; |
| 5266 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5267 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5268 | request1.traffic_annotation = |
| 5269 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5270 | |
| 5271 | HttpRequestInfo request2; |
| 5272 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5273 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5274 | request2.traffic_annotation = |
| 5275 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5276 | |
| 5277 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5278 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5279 | ProxyResolutionService::CreateFixedFromPacResult( |
| 5280 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5281 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5282 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5283 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5284 | |
| 5285 | // Since we have proxy, should try to establish tunnel. |
| 5286 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5287 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5288 | "Host: www.example.org:443\r\n" |
| 5289 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5290 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5291 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5292 | "Host: www.example.org\r\n" |
| 5293 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5294 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5295 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5296 | "Host: www.example.org\r\n" |
| 5297 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5298 | }; |
| 5299 | |
| 5300 | // The proxy responds to the connect with a 407, using a persistent |
| 5301 | // connection. |
| 5302 | MockRead data_reads1[] = { |
| 5303 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5304 | |
| 5305 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5306 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5307 | MockRead(SYNCHRONOUS, "1"), |
| 5308 | |
| 5309 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5310 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5311 | MockRead(SYNCHRONOUS, "22"), |
| 5312 | }; |
| 5313 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5314 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5315 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5316 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5317 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5318 | |
| 5319 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5320 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5321 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5322 | |
| 5323 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5324 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5325 | |
| 5326 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5327 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5328 | |
| 5329 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5330 | ASSERT_TRUE(response1); |
| 5331 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5332 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5333 | |
| 5334 | LoadTimingInfo load_timing_info1; |
| 5335 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5336 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 5337 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 5338 | |
| 5339 | trans1.reset(); |
| 5340 | |
| 5341 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5342 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5343 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5344 | |
| 5345 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5346 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5347 | |
| 5348 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5349 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5350 | |
| 5351 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5352 | ASSERT_TRUE(response2); |
| 5353 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5354 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5355 | |
| 5356 | LoadTimingInfo load_timing_info2; |
| 5357 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5358 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 5359 | |
| 5360 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5361 | |
| 5362 | trans2.reset(); |
| 5363 | session->CloseAllConnections(); |
| 5364 | } |
| 5365 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5366 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5367 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5368 | HttpRequestInfo request; |
| 5369 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5370 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5371 | request.traffic_annotation = |
| 5372 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5373 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5374 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5375 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5376 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5377 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5378 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5379 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5380 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5381 | // Since we have proxy, should use full url |
| 5382 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5383 | MockWrite( |
| 5384 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5385 | "Host: www.example.org\r\n" |
| 5386 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5387 | }; |
| 5388 | |
| 5389 | MockRead data_reads1[] = { |
| 5390 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5391 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5392 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5393 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5394 | }; |
| 5395 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5396 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5397 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5398 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5399 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5400 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5401 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5402 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5403 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5404 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5405 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5406 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5407 | |
| 5408 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5409 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5410 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5411 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5412 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5413 | TestLoadTimingNotReused(load_timing_info, |
| 5414 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5415 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5416 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5417 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5418 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5419 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5420 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5421 | EXPECT_EQ(200, response->headers->response_code()); |
| 5422 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5423 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5424 | |
| 5425 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5426 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5427 | } |
| 5428 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5429 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5430 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5431 | HttpRequestInfo request; |
| 5432 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5433 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5434 | request.traffic_annotation = |
| 5435 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5436 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5437 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5438 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5439 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5440 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5441 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5442 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5443 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5444 | // fetch http://www.example.org/ via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5445 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5446 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5447 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5448 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5449 | spdy::SpdySerializedFrame resp( |
| 5450 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 5451 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5452 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5453 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5454 | }; |
| 5455 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5456 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5457 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5458 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5459 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5460 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5461 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5462 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5463 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5464 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5465 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5466 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5467 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5468 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5469 | |
| 5470 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5471 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5472 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5473 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5474 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5475 | TestLoadTimingNotReused(load_timing_info, |
| 5476 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5477 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5478 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5479 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5480 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5481 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5482 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5483 | |
| 5484 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5485 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5486 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5487 | } |
| 5488 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5489 | // Verifies that a session which races and wins against the owning transaction |
| 5490 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5491 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5492 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5493 | HttpRequestInfo request; |
| 5494 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5495 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5496 | request.traffic_annotation = |
| 5497 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5498 | |
| 5499 | // Configure SPDY proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5500 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5501 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5502 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5503 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5504 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5505 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5506 | // Fetch http://www.example.org/ through the SPDY proxy. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5507 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5508 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5509 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5510 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 5511 | spdy::SpdySerializedFrame resp( |
| 5512 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5513 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5514 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5515 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5516 | }; |
| 5517 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5518 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5519 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5520 | |
| 5521 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5522 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5523 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5524 | |
| 5525 | TestCompletionCallback callback1; |
| 5526 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5527 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5528 | |
| 5529 | // Stall the hostname resolution begun by the transaction. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5530 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5531 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5532 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5533 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5534 | |
| 5535 | // Race a session to the proxy, which completes first. |
| 5536 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 5537 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 5538 | PRIVACY_MODE_DISABLED, |
| 5539 | SpdySessionKey::IsProxySession::kTrue, SocketTag()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5540 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5541 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5542 | |
| 5543 | // Unstall the resolution begun by the transaction. |
| 5544 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5545 | session_deps_.host_resolver->ResolveAllPending(); |
| 5546 | |
| 5547 | EXPECT_FALSE(callback1.have_result()); |
| 5548 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5549 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5550 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5551 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5552 | ASSERT_TRUE(response); |
| 5553 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5554 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5555 | |
| 5556 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5557 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5558 | EXPECT_EQ(kUploadData, response_data); |
| 5559 | } |
| 5560 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5561 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5562 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5563 | HttpRequestInfo request; |
| 5564 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5565 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5566 | request.traffic_annotation = |
| 5567 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5568 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5569 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5570 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5571 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5572 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5573 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5574 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5575 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5576 | // The first request will be a bare GET, the second request will be a |
| 5577 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5578 | spdy_util_.set_default_url(request.url); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5579 | spdy::SpdySerializedFrame req_get( |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5580 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5581 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5582 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5583 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5584 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5585 | spdy::SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5586 | kExtraAuthorizationHeaders, base::size(kExtraAuthorizationHeaders) / 2, 3, |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5587 | LOWEST)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5588 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5589 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5590 | }; |
| 5591 | |
| 5592 | // The first response is a 407 proxy authentication challenge, and the second |
| 5593 | // response will be a 200 response since the second request includes a valid |
| 5594 | // Authorization header. |
| 5595 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5596 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5597 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5598 | spdy::SpdySerializedFrame resp_authentication( |
| 5599 | spdy_util_.ConstructSpdyReplyError( |
| 5600 | "407", kExtraAuthenticationHeaders, |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5601 | base::size(kExtraAuthenticationHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5602 | spdy::SpdySerializedFrame body_authentication( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5603 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5604 | spdy::SpdySerializedFrame resp_data( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 5605 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5606 | spdy::SpdySerializedFrame body_data( |
| 5607 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5608 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5609 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5610 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5611 | CreateMockRead(resp_data, 4), |
| 5612 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5613 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5614 | }; |
| 5615 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5616 | SequencedSocketData data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5617 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5618 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5619 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5620 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5621 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5622 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5623 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5624 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5625 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5626 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5627 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5628 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5629 | |
| 5630 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5631 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5632 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5633 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5634 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5635 | ASSERT_TRUE(response); |
| 5636 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5637 | EXPECT_EQ(407, response->headers->response_code()); |
| 5638 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5639 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5640 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5641 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5642 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5643 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5644 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5645 | |
| 5646 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5647 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5648 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5649 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5650 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5651 | ASSERT_TRUE(response_restart); |
| 5652 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5653 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5654 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5655 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5656 | } |
| 5657 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5658 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5659 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5660 | HttpRequestInfo request; |
| 5661 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5662 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5663 | request.traffic_annotation = |
| 5664 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5665 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5666 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5667 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5668 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5669 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5670 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5671 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5672 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5673 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5674 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5675 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5676 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 5677 | nullptr, 0, 1, LOWEST, 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 | b5e433e | 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( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 5762 | nullptr, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5763 | // fetch https://www.example.org/ via SPDY |
| 5764 | const char kMyUrl[] = "https://www.example.org/"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5765 | spdy::SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5766 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5767 | spdy::SpdySerializedFrame wrapped_get( |
| 5768 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 5769 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 5770 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5771 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 5772 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5773 | spdy::SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5774 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5775 | spdy::SpdySerializedFrame body( |
| 5776 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5777 | spdy::SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5778 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5779 | spdy::SpdySerializedFrame window_update_get_resp( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5780 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5781 | spdy::SpdySerializedFrame window_update_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5782 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5783 | |
| 5784 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5785 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5786 | CreateMockWrite(window_update_get_resp, 6), |
| 5787 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5788 | }; |
| 5789 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5790 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5791 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5792 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5793 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5794 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5795 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5796 | }; |
| 5797 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5798 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5799 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5800 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5801 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5802 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5803 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5804 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5805 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5806 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5807 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5808 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5809 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5810 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5811 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5812 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5813 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5814 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5815 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5816 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5817 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5818 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5819 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5820 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5821 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5822 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5823 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5824 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5825 | ASSERT_TRUE(response); |
| 5826 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5827 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5828 | |
| 5829 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5830 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5831 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5832 | } |
| 5833 | |
| 5834 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5835 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5836 | HttpRequestInfo request; |
| 5837 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5838 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5839 | request.traffic_annotation = |
| 5840 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5841 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5842 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5843 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5844 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5845 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5846 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5847 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5848 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5849 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5850 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5851 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5852 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 5853 | nullptr, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5854 | spdy::SpdySerializedFrame get( |
| 5855 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5856 | |
| 5857 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5858 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5859 | }; |
| 5860 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5861 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
| 5862 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5863 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5864 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5865 | }; |
| 5866 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5867 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5868 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5869 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5870 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5871 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5872 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5873 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5874 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5875 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5876 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5877 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5878 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5879 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5880 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5881 | |
| 5882 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5883 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5884 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5885 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5886 | } |
| 5887 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5888 | // Test the case where a proxied H2 session doesn't exist when an auth challenge |
| 5889 | // is observed, but does exist by the time auth credentials are provided. |
| 5890 | // Proxy-Connection: Close is used so that there's a second DNS lookup, which is |
| 5891 | // what causes the existing H2 session to be noticed and reused. |
| 5892 | TEST_F(HttpNetworkTransactionTest, ProxiedH2SessionAppearsDuringAuth) { |
| 5893 | ProxyConfig proxy_config; |
| 5894 | proxy_config.set_auto_detect(true); |
| 5895 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 5896 | |
| 5897 | CapturingProxyResolver capturing_proxy_resolver; |
| 5898 | capturing_proxy_resolver.set_proxy_server( |
| 5899 | ProxyServer(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 70))); |
| 5900 | session_deps_.proxy_resolution_service = |
| 5901 | std::make_unique<ProxyResolutionService>( |
| 5902 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 5903 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 5904 | std::make_unique<CapturingProxyResolverFactory>( |
| 5905 | &capturing_proxy_resolver), |
| 5906 | nullptr); |
| 5907 | |
| 5908 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 5909 | |
| 5910 | const char kMyUrl[] = "https://www.example.org/"; |
| 5911 | spdy::SpdySerializedFrame get(spdy_util_.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 5912 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 5913 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5914 | spdy::SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 5915 | |
| 5916 | spdy_util_.UpdateWithStreamDestruction(1); |
| 5917 | spdy::SpdySerializedFrame get2( |
| 5918 | spdy_util_.ConstructSpdyGet(kMyUrl, 3, LOWEST)); |
| 5919 | spdy::SpdySerializedFrame get_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 5920 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5921 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
| 5922 | |
| 5923 | MockWrite auth_challenge_writes[] = { |
| 5924 | MockWrite(ASYNC, 0, |
| 5925 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5926 | "Host: www.example.org:443\r\n" |
| 5927 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5928 | }; |
| 5929 | |
| 5930 | MockRead auth_challenge_reads[] = { |
| 5931 | MockRead(ASYNC, 1, |
| 5932 | "HTTP/1.1 407 Authentication Required\r\n" |
| 5933 | "Content-Length: 0\r\n" |
| 5934 | "Proxy-Connection: close\r\n" |
| 5935 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
| 5936 | }; |
| 5937 | |
| 5938 | MockWrite spdy_writes[] = { |
| 5939 | MockWrite(ASYNC, 0, |
| 5940 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5941 | "Host: www.example.org:443\r\n" |
| 5942 | "Proxy-Connection: keep-alive\r\n" |
| 5943 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5944 | CreateMockWrite(get, 2), |
| 5945 | CreateMockWrite(get2, 5), |
| 5946 | }; |
| 5947 | |
| 5948 | MockRead spdy_reads[] = { |
| 5949 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 5950 | CreateMockRead(get_resp, 3, ASYNC), |
| 5951 | CreateMockRead(body, 4, ASYNC), |
| 5952 | CreateMockRead(get_resp2, 6, ASYNC), |
| 5953 | CreateMockRead(body2, 7, ASYNC), |
| 5954 | |
| 5955 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8), |
| 5956 | }; |
| 5957 | |
| 5958 | SequencedSocketData auth_challenge1(auth_challenge_reads, |
| 5959 | auth_challenge_writes); |
| 5960 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge1); |
| 5961 | |
| 5962 | SequencedSocketData auth_challenge2(auth_challenge_reads, |
| 5963 | auth_challenge_writes); |
| 5964 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge2); |
| 5965 | |
| 5966 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
| 5967 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5968 | |
| 5969 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5970 | ssl.next_proto = kProtoHTTP2; |
| 5971 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5972 | |
| 5973 | TestCompletionCallback callback; |
| 5974 | std::string response_data; |
| 5975 | |
| 5976 | // Run first request until an auth challenge is observed. |
| 5977 | HttpRequestInfo request1; |
| 5978 | request1.method = "GET"; |
| 5979 | request1.url = GURL(kMyUrl); |
| 5980 | request1.traffic_annotation = |
| 5981 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5982 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 5983 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 5984 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5985 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 5986 | ASSERT_TRUE(response); |
| 5987 | ASSERT_TRUE(response->headers); |
| 5988 | EXPECT_EQ(407, response->headers->response_code()); |
| 5989 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5990 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 5991 | |
| 5992 | // Run second request until an auth challenge is observed. |
| 5993 | HttpRequestInfo request2; |
| 5994 | request2.method = "GET"; |
| 5995 | request2.url = GURL(kMyUrl); |
| 5996 | request2.traffic_annotation = |
| 5997 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5998 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 5999 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6000 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6001 | response = trans2.GetResponseInfo(); |
| 6002 | ASSERT_TRUE(response); |
| 6003 | ASSERT_TRUE(response->headers); |
| 6004 | EXPECT_EQ(407, response->headers->response_code()); |
| 6005 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6006 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 6007 | |
| 6008 | // Now provide credentials for the first request, and wait for it to complete. |
| 6009 | rv = trans1.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6010 | rv = callback.GetResult(rv); |
| 6011 | EXPECT_THAT(rv, IsOk()); |
| 6012 | response = trans1.GetResponseInfo(); |
| 6013 | ASSERT_TRUE(response); |
| 6014 | ASSERT_TRUE(response->headers); |
| 6015 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6016 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6017 | EXPECT_EQ(kUploadData, response_data); |
| 6018 | |
| 6019 | // Now provide credentials for the second request. It should notice the |
| 6020 | // existing session, and reuse it. |
| 6021 | rv = trans2.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6022 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6023 | response = trans2.GetResponseInfo(); |
| 6024 | ASSERT_TRUE(response); |
| 6025 | ASSERT_TRUE(response->headers); |
| 6026 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6027 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6028 | EXPECT_EQ(kUploadData, response_data); |
| 6029 | } |
| 6030 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6031 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6032 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6033 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6034 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 6035 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6036 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6037 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6038 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6039 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6040 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6041 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6042 | |
| 6043 | HttpRequestInfo request1; |
| 6044 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6045 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6046 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6047 | request1.traffic_annotation = |
| 6048 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6049 | |
| 6050 | HttpRequestInfo request2; |
| 6051 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6052 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6053 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6054 | request2.traffic_annotation = |
| 6055 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6056 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6057 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6058 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 6059 | nullptr, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6060 | spdy::SpdySerializedFrame conn_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 6061 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6062 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6063 | // Fetch https://www.example.org/ via HTTP. |
| 6064 | const char get1[] = |
| 6065 | "GET / HTTP/1.1\r\n" |
| 6066 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6067 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6068 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6069 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6070 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6071 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6072 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6073 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6074 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6075 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6076 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6077 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6078 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6079 | // CONNECT to mail.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6080 | spdy::SpdyHeaderBlock connect2_block; |
| 6081 | connect2_block[spdy::kHttp2MethodHeader] = "CONNECT"; |
| 6082 | connect2_block[spdy::kHttp2AuthorityHeader] = "mail.example.org:443"; |
| 6083 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6084 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 6085 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6086 | spdy::SpdySerializedFrame conn_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 6087 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6088 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6089 | // Fetch https://mail.example.org/ via HTTP. |
| 6090 | const char get2[] = |
| 6091 | "GET / HTTP/1.1\r\n" |
| 6092 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6093 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6094 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6095 | spdy_util_.ConstructSpdyDataFrame(3, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6096 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6097 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6098 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6099 | spdy_util_.ConstructSpdyDataFrame(3, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6100 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6101 | spdy_util_.ConstructSpdyDataFrame(3, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6102 | |
| 6103 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6104 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6105 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6106 | }; |
| 6107 | |
| 6108 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6109 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6110 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 6111 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 6112 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 6113 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 6114 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 6115 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6116 | }; |
| 6117 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6118 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6119 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6120 | |
| 6121 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6122 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6123 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6124 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6125 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6126 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6127 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6128 | |
| 6129 | TestCompletionCallback callback; |
| 6130 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6131 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6132 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6133 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6134 | |
| 6135 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6136 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6137 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6138 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6139 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6140 | ASSERT_TRUE(response); |
| 6141 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6142 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6143 | |
| 6144 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6145 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6146 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6147 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6148 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6149 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6150 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6151 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6152 | |
| 6153 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6154 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6155 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 6156 | // to be created, so the socket's load timing looks like a fresh connection. |
| 6157 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6158 | |
| 6159 | // The requests should have different IDs, since they each are using their own |
| 6160 | // separate stream. |
| 6161 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6162 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6163 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6164 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6165 | } |
| 6166 | |
| 6167 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6168 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6169 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6170 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 6171 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6172 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6173 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6174 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6175 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6176 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6177 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6178 | |
| 6179 | HttpRequestInfo request1; |
| 6180 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6181 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6182 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6183 | request1.traffic_annotation = |
| 6184 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6185 | |
| 6186 | HttpRequestInfo request2; |
| 6187 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6188 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6189 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6190 | request2.traffic_annotation = |
| 6191 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6192 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6193 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6194 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 6195 | nullptr, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6196 | spdy::SpdySerializedFrame conn_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 6197 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6198 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6199 | // Fetch https://www.example.org/ via HTTP. |
| 6200 | const char get1[] = |
| 6201 | "GET / HTTP/1.1\r\n" |
| 6202 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6203 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6204 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6205 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6206 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6207 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6208 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6209 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6210 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6211 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6212 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6213 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6214 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6215 | // Fetch https://www.example.org/2 via HTTP. |
| 6216 | const char get2[] = |
| 6217 | "GET /2 HTTP/1.1\r\n" |
| 6218 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6219 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6220 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6221 | spdy_util_.ConstructSpdyDataFrame(1, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6222 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6223 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6224 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6225 | spdy_util_.ConstructSpdyDataFrame(1, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6226 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6227 | spdy_util_.ConstructSpdyDataFrame(1, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6228 | |
| 6229 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6230 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6231 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6232 | }; |
| 6233 | |
| 6234 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6235 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6236 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6237 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6238 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6239 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6240 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6241 | }; |
| 6242 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6243 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6244 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6245 | |
| 6246 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6247 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6248 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6249 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6250 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6251 | |
| 6252 | TestCompletionCallback callback; |
| 6253 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6254 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6255 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6256 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6257 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6258 | |
| 6259 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6260 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6261 | |
| 6262 | LoadTimingInfo load_timing_info; |
| 6263 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6264 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6265 | |
| 6266 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6267 | ASSERT_TRUE(response); |
| 6268 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6269 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6270 | |
| 6271 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6272 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6273 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6274 | trans.reset(); |
| 6275 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6276 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6277 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6278 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6279 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6280 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6281 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6282 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6283 | |
| 6284 | LoadTimingInfo load_timing_info2; |
| 6285 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 6286 | TestLoadTimingReused(load_timing_info2); |
| 6287 | |
| 6288 | // The requests should have the same ID. |
| 6289 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6290 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6291 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6292 | } |
| 6293 | |
| 6294 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 6295 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6296 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6297 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6298 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6299 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6300 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6301 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6302 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6303 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6304 | |
| 6305 | HttpRequestInfo request1; |
| 6306 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6307 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6308 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6309 | request1.traffic_annotation = |
| 6310 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6311 | |
| 6312 | HttpRequestInfo request2; |
| 6313 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6314 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6315 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6316 | request2.traffic_annotation = |
| 6317 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6318 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6319 | // http://www.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6320 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6321 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6322 | spdy::SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6323 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6324 | spdy::SpdySerializedFrame get_resp1( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 6325 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6326 | spdy::SpdySerializedFrame body1( |
| 6327 | spdy_util_.ConstructSpdyDataFrame(1, "1", true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 6328 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6329 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6330 | // http://mail.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6331 | spdy::SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6332 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6333 | spdy::SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6334 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6335 | spdy::SpdySerializedFrame get_resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 6336 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6337 | spdy::SpdySerializedFrame body2( |
| 6338 | spdy_util_.ConstructSpdyDataFrame(3, "22", true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6339 | |
| 6340 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6341 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6342 | }; |
| 6343 | |
| 6344 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6345 | CreateMockRead(get_resp1, 1, ASYNC), |
| 6346 | CreateMockRead(body1, 2, ASYNC), |
| 6347 | CreateMockRead(get_resp2, 4, ASYNC), |
| 6348 | CreateMockRead(body2, 5, ASYNC), |
| 6349 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6350 | }; |
| 6351 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6352 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6353 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6354 | |
| 6355 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6356 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6357 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6358 | |
| 6359 | TestCompletionCallback callback; |
| 6360 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6361 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6362 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6363 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6364 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6365 | |
| 6366 | LoadTimingInfo load_timing_info; |
| 6367 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6368 | TestLoadTimingNotReused(load_timing_info, |
| 6369 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6370 | |
| 6371 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6372 | ASSERT_TRUE(response); |
| 6373 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6374 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6375 | |
| 6376 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6377 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6378 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 6379 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6380 | // Delete the first request, so the second one can reuse the socket. |
| 6381 | trans.reset(); |
| 6382 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6383 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6384 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6385 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6386 | |
| 6387 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6388 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6389 | TestLoadTimingReused(load_timing_info2); |
| 6390 | |
| 6391 | // The requests should have the same ID. |
| 6392 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6393 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6394 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6395 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6396 | } |
| 6397 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6398 | // Test that an HTTP/2 CONNECT through an HTTPS Proxy to a HTTP/2 server and a |
| 6399 | // direct (non-proxied) request to the proxy server are not pooled, as that |
| 6400 | // would break socket pool isolation. |
| 6401 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation1) { |
| 6402 | ProxyConfig proxy_config; |
| 6403 | proxy_config.set_auto_detect(true); |
| 6404 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6405 | |
| 6406 | CapturingProxyResolver capturing_proxy_resolver; |
| 6407 | session_deps_.proxy_resolution_service = |
| 6408 | std::make_unique<ProxyResolutionService>( |
| 6409 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6410 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6411 | std::make_unique<CapturingProxyResolverFactory>( |
| 6412 | &capturing_proxy_resolver), |
| 6413 | nullptr); |
| 6414 | |
| 6415 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6416 | |
| 6417 | SpdyTestUtil spdy_util1; |
| 6418 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6419 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 6420 | nullptr, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6421 | // fetch https://www.example.org/ via HTTP/2. |
| 6422 | const char kMyUrl[] = "https://www.example.org/"; |
| 6423 | spdy::SpdySerializedFrame get(spdy_util1.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6424 | spdy::SpdySerializedFrame wrapped_get( |
| 6425 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6426 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 6427 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6428 | spdy::SpdySerializedFrame get_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 6429 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6430 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6431 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6432 | spdy::SpdySerializedFrame body(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6433 | spdy::SpdySerializedFrame wrapped_body( |
| 6434 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6435 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6436 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6437 | spdy::SpdySerializedFrame window_update_body( |
| 6438 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6439 | |
| 6440 | MockWrite spdy_writes1[] = { |
| 6441 | CreateMockWrite(connect, 0), |
| 6442 | CreateMockWrite(wrapped_get, 2), |
| 6443 | CreateMockWrite(window_update_get_resp, 6), |
| 6444 | CreateMockWrite(window_update_body, 7), |
| 6445 | }; |
| 6446 | |
| 6447 | MockRead spdy_reads1[] = { |
| 6448 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6449 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6450 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6451 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6452 | MockRead(ASYNC, 0, 8), |
| 6453 | }; |
| 6454 | |
| 6455 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6456 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6457 | |
| 6458 | // Fetch https://proxy:70/ via HTTP/2. Needs a new SpdyTestUtil, since it uses |
| 6459 | // a new pipe. |
| 6460 | SpdyTestUtil spdy_util2; |
| 6461 | spdy::SpdySerializedFrame req( |
| 6462 | spdy_util2.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6463 | MockWrite spdy_writes2[] = {CreateMockWrite(req, 0)}; |
| 6464 | |
| 6465 | spdy::SpdySerializedFrame resp( |
| 6466 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6467 | spdy::SpdySerializedFrame data(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6468 | MockRead spdy_reads2[] = { |
| 6469 | CreateMockRead(resp, 1), |
| 6470 | CreateMockRead(data, 2), |
| 6471 | MockRead(ASYNC, 0, 3), |
| 6472 | }; |
| 6473 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6474 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6475 | |
| 6476 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6477 | ssl.next_proto = kProtoHTTP2; |
| 6478 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6479 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6480 | ssl2.next_proto = kProtoHTTP2; |
| 6481 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6482 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6483 | ssl3.next_proto = kProtoHTTP2; |
| 6484 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6485 | |
| 6486 | TestCompletionCallback callback; |
| 6487 | std::string response_data; |
| 6488 | |
| 6489 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6490 | capturing_proxy_resolver.set_proxy_server( |
| 6491 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6492 | HttpRequestInfo request1; |
| 6493 | request1.method = "GET"; |
| 6494 | request1.url = GURL("https://www.example.org/"); |
| 6495 | request1.traffic_annotation = |
| 6496 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6497 | |
| 6498 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6499 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 6500 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6501 | |
| 6502 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6503 | base::RunLoop().RunUntilIdle(); |
| 6504 | // Now allow the read of the response to complete. |
| 6505 | spdy_data1.Resume(); |
| 6506 | rv = callback.WaitForResult(); |
| 6507 | EXPECT_THAT(rv, IsOk()); |
| 6508 | |
| 6509 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 6510 | ASSERT_TRUE(response); |
| 6511 | ASSERT_TRUE(response->headers); |
| 6512 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6513 | |
| 6514 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6515 | EXPECT_EQ(kUploadData, response_data); |
| 6516 | RunUntilIdle(); |
| 6517 | |
| 6518 | // Make a direct HTTP/2 request to proxy:70. |
| 6519 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6520 | HttpRequestInfo request2; |
| 6521 | request2.method = "GET"; |
| 6522 | request2.url = GURL("https://proxy:70/"); |
| 6523 | request2.traffic_annotation = |
| 6524 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6525 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6526 | EXPECT_THAT(callback.GetResult(trans2.Start(&request2, callback.callback(), |
| 6527 | NetLogWithSource())), |
| 6528 | IsOk()); |
| 6529 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6530 | } |
| 6531 | |
| 6532 | // Same as above, but reverse request order, since the code to check for an |
| 6533 | // existing session is different for tunnels and direct connections. |
| 6534 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation2) { |
| 6535 | // Configure against https proxy server "myproxy:80". |
| 6536 | ProxyConfig proxy_config; |
| 6537 | proxy_config.set_auto_detect(true); |
| 6538 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6539 | |
| 6540 | CapturingProxyResolver capturing_proxy_resolver; |
| 6541 | session_deps_.proxy_resolution_service = |
| 6542 | std::make_unique<ProxyResolutionService>( |
| 6543 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6544 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6545 | std::make_unique<CapturingProxyResolverFactory>( |
| 6546 | &capturing_proxy_resolver), |
| 6547 | nullptr); |
| 6548 | |
| 6549 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6550 | // Fetch https://proxy:70/ via HTTP/2. |
| 6551 | SpdyTestUtil spdy_util1; |
| 6552 | spdy::SpdySerializedFrame req( |
| 6553 | spdy_util1.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6554 | MockWrite spdy_writes1[] = {CreateMockWrite(req, 0)}; |
| 6555 | |
| 6556 | spdy::SpdySerializedFrame resp( |
| 6557 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6558 | spdy::SpdySerializedFrame data(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6559 | MockRead spdy_reads1[] = { |
| 6560 | CreateMockRead(resp, 1), |
| 6561 | CreateMockRead(data, 2), |
| 6562 | MockRead(ASYNC, 0, 3), |
| 6563 | }; |
| 6564 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6565 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6566 | |
| 6567 | SpdyTestUtil spdy_util2; |
| 6568 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6569 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
| 6570 | nullptr, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 6571 | // fetch https://www.example.org/ via HTTP/2. |
| 6572 | const char kMyUrl[] = "https://www.example.org/"; |
| 6573 | spdy::SpdySerializedFrame get(spdy_util2.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6574 | spdy::SpdySerializedFrame wrapped_get( |
| 6575 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6576 | spdy::SpdySerializedFrame conn_resp( |
| 6577 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6578 | spdy::SpdySerializedFrame get_resp( |
| 6579 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6580 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6581 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6582 | spdy::SpdySerializedFrame body(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6583 | spdy::SpdySerializedFrame wrapped_body( |
| 6584 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6585 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6586 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6587 | spdy::SpdySerializedFrame window_update_body( |
| 6588 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6589 | |
| 6590 | MockWrite spdy_writes2[] = { |
| 6591 | CreateMockWrite(connect, 0), |
| 6592 | CreateMockWrite(wrapped_get, 2), |
| 6593 | CreateMockWrite(window_update_get_resp, 6), |
| 6594 | CreateMockWrite(window_update_body, 7), |
| 6595 | }; |
| 6596 | |
| 6597 | MockRead spdy_reads2[] = { |
| 6598 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6599 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6600 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6601 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6602 | MockRead(ASYNC, 0, 8), |
| 6603 | }; |
| 6604 | |
| 6605 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6606 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6607 | |
| 6608 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6609 | ssl.next_proto = kProtoHTTP2; |
| 6610 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6611 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6612 | ssl2.next_proto = kProtoHTTP2; |
| 6613 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6614 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6615 | ssl3.next_proto = kProtoHTTP2; |
| 6616 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6617 | |
| 6618 | TestCompletionCallback callback; |
| 6619 | std::string response_data; |
| 6620 | |
| 6621 | // Make a direct HTTP/2 request to proxy:70. |
| 6622 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6623 | HttpRequestInfo request1; |
| 6624 | request1.method = "GET"; |
| 6625 | request1.url = GURL("https://proxy:70/"); |
| 6626 | request1.traffic_annotation = |
| 6627 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6628 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6629 | EXPECT_THAT(callback.GetResult(trans1.Start(&request1, callback.callback(), |
| 6630 | NetLogWithSource())), |
| 6631 | IsOk()); |
| 6632 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6633 | RunUntilIdle(); |
| 6634 | |
| 6635 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6636 | capturing_proxy_resolver.set_proxy_server( |
| 6637 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6638 | HttpRequestInfo request2; |
| 6639 | request2.method = "GET"; |
| 6640 | request2.url = GURL("https://www.example.org/"); |
| 6641 | request2.traffic_annotation = |
| 6642 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6643 | |
| 6644 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6645 | int rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6646 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6647 | |
| 6648 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6649 | base::RunLoop().RunUntilIdle(); |
| 6650 | // Now allow the read of the response to complete. |
| 6651 | spdy_data2.Resume(); |
| 6652 | rv = callback.WaitForResult(); |
| 6653 | EXPECT_THAT(rv, IsOk()); |
| 6654 | |
| 6655 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 6656 | ASSERT_TRUE(response2); |
| 6657 | ASSERT_TRUE(response2->headers); |
| 6658 | EXPECT_EQ("HTTP/1.1 200", response2->headers->GetStatusLine()); |
| 6659 | |
| 6660 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6661 | EXPECT_EQ(kUploadData, response_data); |
| 6662 | } |
| 6663 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6664 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6665 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6666 | HttpRequestInfo request; |
| 6667 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6668 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6669 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6670 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6671 | request.traffic_annotation = |
| 6672 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6673 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6674 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6675 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6676 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6677 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6678 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6679 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6680 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6681 | // Since we have proxy, should use full url |
| 6682 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6683 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6684 | "Host: www.example.org\r\n" |
| 6685 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6686 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6687 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6688 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6689 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6690 | "Host: www.example.org\r\n" |
| 6691 | "Proxy-Connection: keep-alive\r\n" |
| 6692 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6693 | }; |
| 6694 | |
| 6695 | // The proxy responds to the GET with a 407, using a persistent |
| 6696 | // connection. |
| 6697 | MockRead data_reads1[] = { |
| 6698 | // No credentials. |
| 6699 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 6700 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6701 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 6702 | MockRead("Content-Length: 0\r\n\r\n"), |
| 6703 | |
| 6704 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6705 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6706 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6707 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6708 | }; |
| 6709 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6710 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6711 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6712 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6713 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6714 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6715 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6716 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6717 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6718 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6719 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6720 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6721 | |
| 6722 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6723 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6724 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6725 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6726 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6727 | TestLoadTimingNotReused(load_timing_info, |
| 6728 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6729 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6730 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6731 | ASSERT_TRUE(response); |
| 6732 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6733 | EXPECT_EQ(407, response->headers->response_code()); |
| 6734 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 6735 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6736 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6737 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6738 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6739 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6740 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6741 | |
| 6742 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6743 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6744 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6745 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6746 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6747 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 6748 | TestLoadTimingReused(load_timing_info); |
| 6749 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6750 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6751 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6752 | |
| 6753 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6754 | EXPECT_EQ(200, response->headers->response_code()); |
| 6755 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6756 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6757 | |
| 6758 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6759 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6760 | } |
| 6761 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6762 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6763 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6764 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6765 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6766 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6767 | request.traffic_annotation = |
| 6768 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6769 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6770 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6771 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6772 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6773 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6774 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6775 | // Since we have proxy, should try to establish tunnel. |
| 6776 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6777 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6778 | "Host: www.example.org:443\r\n" |
| 6779 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6780 | }; |
| 6781 | |
| 6782 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6783 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 6784 | // No response body because the test stops reading here. |
| 6785 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6786 | }; |
| 6787 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6788 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6789 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6790 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6791 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6792 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6793 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6794 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6795 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6796 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6797 | |
| 6798 | rv = callback.WaitForResult(); |
| 6799 | EXPECT_EQ(expected_status, rv); |
| 6800 | } |
| 6801 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6802 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6803 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6804 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6805 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6806 | } |
| 6807 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6808 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6809 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 6810 | } |
| 6811 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6812 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6813 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 6814 | } |
| 6815 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6816 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6817 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 6818 | } |
| 6819 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6820 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6821 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 6822 | } |
| 6823 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6824 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6825 | ConnectStatusHelper( |
| 6826 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 6827 | } |
| 6828 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6829 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6830 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 6831 | } |
| 6832 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6833 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6834 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 6835 | } |
| 6836 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6837 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6838 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 6839 | } |
| 6840 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6841 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6842 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 6843 | } |
| 6844 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6845 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6846 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 6847 | } |
| 6848 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6849 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6850 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 6851 | } |
| 6852 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6853 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6854 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 6855 | } |
| 6856 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6857 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6858 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 6859 | } |
| 6860 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6861 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6862 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 6863 | } |
| 6864 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6865 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6866 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 6867 | } |
| 6868 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6869 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6870 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 6871 | } |
| 6872 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6873 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 6874 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 6875 | } |
| 6876 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6877 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6878 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 6879 | } |
| 6880 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6881 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6882 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 6883 | } |
| 6884 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6885 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6886 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 6887 | } |
| 6888 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6889 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6890 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 6891 | } |
| 6892 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6893 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6894 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 6895 | } |
| 6896 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6897 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6898 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 6899 | } |
| 6900 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6901 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6902 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 6903 | } |
| 6904 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6905 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6906 | ConnectStatusHelperWithExpectedStatus( |
| 6907 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 6908 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6909 | } |
| 6910 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6911 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6912 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 6913 | } |
| 6914 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6915 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6916 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 6917 | } |
| 6918 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6919 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6920 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 6921 | } |
| 6922 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6923 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6924 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 6925 | } |
| 6926 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6927 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6928 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 6929 | } |
| 6930 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6931 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6932 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 6933 | } |
| 6934 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6935 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6936 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 6937 | } |
| 6938 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6939 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6940 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 6941 | } |
| 6942 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6943 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6944 | ConnectStatusHelper( |
| 6945 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 6946 | } |
| 6947 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6948 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6949 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 6950 | } |
| 6951 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6952 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6953 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 6954 | } |
| 6955 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6956 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6957 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 6958 | } |
| 6959 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6960 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6961 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 6962 | } |
| 6963 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6964 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6965 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 6966 | } |
| 6967 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6968 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6969 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 6970 | } |
| 6971 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6972 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6973 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 6974 | } |
| 6975 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6976 | // Test the flow when both the proxy server AND origin server require |
| 6977 | // authentication. Again, this uses basic auth for both since that is |
| 6978 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6979 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6980 | HttpRequestInfo request; |
| 6981 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6982 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6983 | request.traffic_annotation = |
| 6984 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6985 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6986 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6987 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6988 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6989 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6990 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6991 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6992 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6993 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6994 | MockWrite( |
| 6995 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6996 | "Host: www.example.org\r\n" |
| 6997 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6998 | }; |
| 6999 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7000 | MockRead data_reads1[] = { |
| 7001 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 7002 | // Give a couple authenticate options (only the middle one is actually |
| 7003 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 7004 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7005 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7006 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 7007 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7008 | // Large content-length -- won't matter, as connection will be reset. |
| 7009 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7010 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7011 | }; |
| 7012 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7013 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7014 | // request we should be issuing -- the final header line contains the |
| 7015 | // proxy's credentials. |
| 7016 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7017 | MockWrite( |
| 7018 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7019 | "Host: www.example.org\r\n" |
| 7020 | "Proxy-Connection: keep-alive\r\n" |
| 7021 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7022 | }; |
| 7023 | |
| 7024 | // Now the proxy server lets the request pass through to origin server. |
| 7025 | // The origin server responds with a 401. |
| 7026 | MockRead data_reads2[] = { |
| 7027 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7028 | // Note: We are using the same realm-name as the proxy server. This is |
| 7029 | // completely valid, as realms are unique across hosts. |
| 7030 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7031 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7032 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7033 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7034 | }; |
| 7035 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7036 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7037 | // the credentials for both the proxy and origin server. |
| 7038 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7039 | MockWrite( |
| 7040 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7041 | "Host: www.example.org\r\n" |
| 7042 | "Proxy-Connection: keep-alive\r\n" |
| 7043 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 7044 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7045 | }; |
| 7046 | |
| 7047 | // Lastly we get the desired content. |
| 7048 | MockRead data_reads3[] = { |
| 7049 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7050 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7051 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7052 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7053 | }; |
| 7054 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7055 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7056 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7057 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7058 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7059 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7060 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7061 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7062 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7063 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7064 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7065 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7066 | |
| 7067 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7068 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7069 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7070 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7071 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7072 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7073 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7074 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7075 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7076 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7077 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7078 | |
| 7079 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7080 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7081 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7082 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7083 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7084 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7085 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7086 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7087 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7088 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7089 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7090 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7091 | |
| 7092 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7093 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7094 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7095 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7096 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7097 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7098 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7099 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7100 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 7101 | // can't hook into its internals to cause it to generate predictable NTLM |
| 7102 | // authorization headers. |
| 7103 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7104 | // The NTLM authentication unit tests are based on known test data from the |
| 7105 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 7106 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 7107 | // for the implementation and testing of the protocol. |
| 7108 | // |
| 7109 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7110 | |
| 7111 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7112 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7113 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7114 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7115 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7116 | request.traffic_annotation = |
| 7117 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7118 | |
| 7119 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7120 | // to other auth schemes. |
| 7121 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7122 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7123 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7124 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7125 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7126 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7127 | // Generate the NTLM messages based on known test data. |
| 7128 | std::string negotiate_msg; |
| 7129 | std::string challenge_msg; |
| 7130 | std::string authenticate_msg; |
| 7131 | base::Base64Encode( |
| 7132 | base::StringPiece( |
| 7133 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7134 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7135 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7136 | base::Base64Encode( |
| 7137 | base::StringPiece( |
| 7138 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7139 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7140 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7141 | base::Base64Encode( |
| 7142 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7143 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7144 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7145 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7146 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7147 | &authenticate_msg); |
| 7148 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7149 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7150 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7151 | "Host: server\r\n" |
| 7152 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7153 | }; |
| 7154 | |
| 7155 | MockRead data_reads1[] = { |
| 7156 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7157 | // Negotiate and NTLM are often requested together. However, we only want |
| 7158 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7159 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7160 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7161 | MockRead("Connection: close\r\n"), |
| 7162 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7163 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7164 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7165 | }; |
| 7166 | |
| 7167 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7168 | // After restarting with a null identity, this is the |
| 7169 | // request we should be issuing -- the final header line contains a Type |
| 7170 | // 1 message. |
| 7171 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7172 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7173 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7174 | "Authorization: NTLM "), |
| 7175 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7176 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7177 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7178 | // (using correct credentials). The second request continues on the |
| 7179 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7180 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7181 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7182 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7183 | "Authorization: NTLM "), |
| 7184 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7185 | }; |
| 7186 | |
| 7187 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7188 | // The origin server responds with a Type 2 message. |
| 7189 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7190 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7191 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7192 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7193 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7194 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7195 | // Lastly we get the desired content. |
| 7196 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7197 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7198 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7199 | }; |
| 7200 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7201 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7202 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7203 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7204 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7205 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7206 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7207 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7208 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7209 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7210 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7211 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7212 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7213 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7214 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7215 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7216 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7217 | |
| 7218 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7219 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7220 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7221 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7222 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7223 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7224 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7225 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7226 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7227 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7228 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7229 | rv = trans.RestartWithAuth( |
| 7230 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7231 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7232 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7233 | |
| 7234 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7235 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7236 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7237 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7238 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7239 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7240 | ASSERT_TRUE(response); |
| 7241 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7242 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7243 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7244 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7245 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7246 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7247 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7248 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7249 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7250 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7251 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7252 | ASSERT_TRUE(response); |
| 7253 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7254 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7255 | |
| 7256 | std::string response_data; |
| 7257 | rv = ReadTransaction(&trans, &response_data); |
| 7258 | EXPECT_THAT(rv, IsOk()); |
| 7259 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7260 | |
| 7261 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7262 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7263 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7264 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7265 | } |
| 7266 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7267 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7268 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7269 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7270 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7271 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7272 | request.traffic_annotation = |
| 7273 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7274 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7275 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7276 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7277 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7278 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7279 | // Generate the NTLM messages based on known test data. |
| 7280 | std::string negotiate_msg; |
| 7281 | std::string challenge_msg; |
| 7282 | std::string authenticate_msg; |
| 7283 | base::Base64Encode( |
| 7284 | base::StringPiece( |
| 7285 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7286 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7287 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7288 | base::Base64Encode( |
| 7289 | base::StringPiece( |
| 7290 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7291 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7292 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7293 | base::Base64Encode( |
| 7294 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7295 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7296 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7297 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7298 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7299 | &authenticate_msg); |
| 7300 | |
| 7301 | // The authenticate message when |kWrongPassword| is sent. |
| 7302 | std::string wrong_password_authenticate_msg( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7303 | "TlRMTVNTUAADAAAAGAAYAFgAAACKAIoAcAAAAAwADAD6AAAACAAIAAYBAAAQABAADgEAAAAA" |
| 7304 | "AABYAAAAA4IIAAAAAAAAAAAAAPknEYqtJQtusopDRSfYzAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 7305 | "AAAAAOtVz38osnFdRRggUQHUJ3EBAQAAAAAAAIALyP0A1NIBqqqqqqqqqqoAAAAAAgAMAEQA" |
| 7306 | "bwBtAGEAaQBuAAEADABTAGUAcgB2AGUAcgAGAAQAAgAAAAoAEAAAAAAAAAAAAAAAAAAAAAAA" |
| 7307 | "CQAWAEgAVABUAFAALwBzAGUAcgB2AGUAcgAAAAAAAAAAAEQAbwBtAGEAaQBuAFUAcwBlAHIA" |
| 7308 | "QwBPAE0AUABVAFQARQBSAA=="); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7309 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7310 | // Sanity check that it's the same length as the correct authenticate message |
| 7311 | // and that it's different. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7312 | ASSERT_EQ(authenticate_msg.length(), |
| 7313 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7314 | ASSERT_NE(authenticate_msg, wrong_password_authenticate_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7315 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7316 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7317 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7318 | "Host: server\r\n" |
| 7319 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7320 | }; |
| 7321 | |
| 7322 | MockRead data_reads1[] = { |
| 7323 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7324 | // Negotiate and NTLM are often requested together. However, we only want |
| 7325 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7326 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7327 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7328 | MockRead("Connection: close\r\n"), |
| 7329 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7330 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7331 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7332 | }; |
| 7333 | |
| 7334 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7335 | // After restarting with a null identity, this is the |
| 7336 | // request we should be issuing -- the final header line contains a Type |
| 7337 | // 1 message. |
| 7338 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7339 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7340 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7341 | "Authorization: NTLM "), |
| 7342 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7343 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7344 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7345 | // (using incorrect credentials). The second request continues on the |
| 7346 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7347 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7348 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7349 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7350 | "Authorization: NTLM "), |
| 7351 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7352 | }; |
| 7353 | |
| 7354 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7355 | // The origin server responds with a Type 2 message. |
| 7356 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7357 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7358 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 7359 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7360 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7361 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7362 | // Wrong password. |
| 7363 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7364 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 7365 | MockRead("Content-Length: 42\r\n"), |
| 7366 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7367 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7368 | }; |
| 7369 | |
| 7370 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7371 | // After restarting with a null identity, this is the |
| 7372 | // request we should be issuing -- the final header line contains a Type |
| 7373 | // 1 message. |
| 7374 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7375 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7376 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7377 | "Authorization: NTLM "), |
| 7378 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7379 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7380 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7381 | // (the credentials for the origin server). The second request continues |
| 7382 | // on the same connection. |
| 7383 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7384 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7385 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7386 | "Authorization: NTLM "), |
| 7387 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7388 | }; |
| 7389 | |
| 7390 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7391 | // The origin server responds with a Type 2 message. |
| 7392 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7393 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7394 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7395 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7396 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7397 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7398 | // Lastly we get the desired content. |
| 7399 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7400 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7401 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7402 | }; |
| 7403 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7404 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7405 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7406 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7407 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7408 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7409 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7410 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7411 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7412 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7413 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7414 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7415 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 7416 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 7417 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7418 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7419 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7420 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7421 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7422 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7423 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7424 | |
| 7425 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7426 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7427 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7428 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7429 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7430 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7431 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7432 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7433 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7434 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7435 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7436 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7437 | rv = trans.RestartWithAuth( |
| 7438 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 7439 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7440 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7441 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7442 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7443 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7444 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7445 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7446 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7447 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7448 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7449 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7450 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7451 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7452 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7453 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7454 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7455 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7456 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7457 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7458 | |
| 7459 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7460 | rv = trans.RestartWithAuth( |
| 7461 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7462 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7463 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7464 | |
| 7465 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7466 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7467 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7468 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7469 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7470 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7471 | |
| 7472 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7473 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7474 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7475 | |
| 7476 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7477 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7478 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7479 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7480 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7481 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7482 | |
| 7483 | std::string response_data; |
| 7484 | rv = ReadTransaction(&trans, &response_data); |
| 7485 | EXPECT_THAT(rv, IsOk()); |
| 7486 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7487 | |
| 7488 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7489 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7490 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7491 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 7492 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 7493 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7494 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7495 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7496 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 7497 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7498 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7499 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7500 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7501 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7502 | const char* kUrl = "https://server/kids/login.aspx"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7503 | |
| 7504 | HttpRequestInfo request; |
| 7505 | request.method = "GET"; |
| 7506 | request.url = GURL(kUrl); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7507 | request.traffic_annotation = |
| 7508 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7509 | |
| 7510 | // First request without credentials. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7511 | spdy::SpdyHeaderBlock request_headers0( |
| 7512 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 7513 | spdy::SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7514 | 1, std::move(request_headers0), LOWEST, true)); |
| 7515 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7516 | spdy::SpdyHeaderBlock response_headers0; |
| 7517 | response_headers0[spdy::kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7518 | response_headers0["www-authenticate"] = "NTLM"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7519 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7520 | 1, std::move(response_headers0), true)); |
| 7521 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7522 | // Stream 1 is closed. |
| 7523 | spdy_util_.UpdateWithStreamDestruction(1); |
| 7524 | |
| 7525 | // Generate the NTLM messages based on known test data. |
| 7526 | std::string negotiate_msg; |
| 7527 | std::string challenge_msg; |
| 7528 | std::string authenticate_msg; |
| 7529 | base::Base64Encode( |
| 7530 | base::StringPiece( |
| 7531 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7532 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7533 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7534 | base::Base64Encode( |
| 7535 | base::StringPiece( |
| 7536 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7537 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7538 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7539 | base::Base64Encode( |
| 7540 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7541 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7542 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7543 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7544 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7545 | &authenticate_msg); |
| 7546 | |
| 7547 | // Retry with authorization header. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7548 | spdy::SpdyHeaderBlock request_headers1( |
| 7549 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7550 | request_headers1["authorization"] = std::string("NTLM ") + negotiate_msg; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7551 | spdy::SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7552 | 3, std::move(request_headers1), LOWEST, true)); |
| 7553 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7554 | spdy::SpdySerializedFrame rst( |
| 7555 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_HTTP_1_1_REQUIRED)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7556 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7557 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
| 7558 | MockRead reads0[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7559 | |
| 7560 | // Retry yet again using HTTP/1.1. |
| 7561 | MockWrite writes1[] = { |
| 7562 | // After restarting with a null identity, this is the |
| 7563 | // request we should be issuing -- the final header line contains a Type |
| 7564 | // 1 message. |
| 7565 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7566 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7567 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7568 | "Authorization: NTLM "), |
| 7569 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7570 | |
| 7571 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7572 | // (the credentials for the origin server). The second request continues |
| 7573 | // on the same connection. |
| 7574 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7575 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7576 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7577 | "Authorization: NTLM "), |
| 7578 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7579 | }; |
| 7580 | |
| 7581 | MockRead reads1[] = { |
| 7582 | // The origin server responds with a Type 2 message. |
| 7583 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7584 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7585 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7586 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7587 | MockRead("You are not authorized to view this page\r\n"), |
| 7588 | |
| 7589 | // Lastly we get the desired content. |
| 7590 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7591 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7592 | 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] | 7593 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7594 | SequencedSocketData data0(reads0, writes0); |
| 7595 | StaticSocketDataProvider data1(reads1, writes1); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7596 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 7597 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7598 | |
| 7599 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 7600 | ssl0.next_proto = kProtoHTTP2; |
| 7601 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7602 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 7603 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7604 | |
| 7605 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7606 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7607 | |
| 7608 | TestCompletionCallback callback1; |
| 7609 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 7610 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7611 | |
| 7612 | rv = callback1.WaitForResult(); |
| 7613 | EXPECT_THAT(rv, IsOk()); |
| 7614 | |
| 7615 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7616 | |
| 7617 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7618 | ASSERT_TRUE(response); |
| 7619 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
| 7620 | |
| 7621 | TestCompletionCallback callback2; |
| 7622 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7623 | rv = trans.RestartWithAuth( |
| 7624 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7625 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7626 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7627 | |
| 7628 | rv = callback2.WaitForResult(); |
| 7629 | EXPECT_THAT(rv, IsOk()); |
| 7630 | |
| 7631 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7632 | |
| 7633 | response = trans.GetResponseInfo(); |
| 7634 | ASSERT_TRUE(response); |
| 7635 | EXPECT_FALSE(response->auth_challenge); |
| 7636 | |
| 7637 | TestCompletionCallback callback3; |
| 7638 | |
| 7639 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 7640 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7641 | |
| 7642 | rv = callback3.WaitForResult(); |
| 7643 | EXPECT_THAT(rv, IsOk()); |
| 7644 | |
| 7645 | response = trans.GetResponseInfo(); |
| 7646 | ASSERT_TRUE(response); |
| 7647 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7648 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7649 | |
| 7650 | std::string response_data; |
| 7651 | rv = ReadTransaction(&trans, &response_data); |
| 7652 | EXPECT_THAT(rv, IsOk()); |
| 7653 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7654 | |
| 7655 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 7656 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 7657 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7658 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7659 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7660 | |
| 7661 | // Test that, if we have an NTLM proxy and the origin resets the connection, we |
| 7662 | // do no retry forever checking for TLS version interference. This is a |
| 7663 | // regression test for https://crbug.com/823387. |
| 7664 | TEST_F(HttpNetworkTransactionTest, NTLMProxyTLSHandshakeReset) { |
| 7665 | // The NTLM test data expects the proxy to be named 'server'. The origin is |
| 7666 | // https://origin/. |
| 7667 | session_deps_.proxy_resolution_service = |
| 7668 | ProxyResolutionService::CreateFixedFromPacResult( |
| 7669 | "PROXY server", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7670 | |
| 7671 | SSLConfig config; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7672 | session_deps_.ssl_config_service = |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 7673 | std::make_unique<TestSSLConfigService>(config); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7674 | |
| 7675 | HttpRequestInfo request; |
| 7676 | request.method = "GET"; |
| 7677 | request.url = GURL("https://origin/"); |
| 7678 | request.traffic_annotation = |
| 7679 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7680 | |
| 7681 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7682 | // to other auth schemes. |
| 7683 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 7684 | |
| 7685 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7686 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
| 7687 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7688 | |
| 7689 | // Generate the NTLM messages based on known test data. |
| 7690 | std::string negotiate_msg; |
| 7691 | std::string challenge_msg; |
| 7692 | std::string authenticate_msg; |
| 7693 | base::Base64Encode( |
| 7694 | base::StringPiece( |
| 7695 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7696 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7697 | &negotiate_msg); |
| 7698 | base::Base64Encode( |
| 7699 | base::StringPiece( |
| 7700 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7701 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7702 | &challenge_msg); |
| 7703 | base::Base64Encode( |
| 7704 | base::StringPiece( |
| 7705 | reinterpret_cast<const char*>( |
| 7706 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7707 | base::size( |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7708 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
| 7709 | &authenticate_msg); |
| 7710 | |
| 7711 | MockWrite data_writes[] = { |
| 7712 | // The initial CONNECT request. |
| 7713 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7714 | "Host: origin:443\r\n" |
| 7715 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7716 | |
| 7717 | // After restarting with an identity. |
| 7718 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7719 | "Host: origin:443\r\n" |
| 7720 | "Proxy-Connection: keep-alive\r\n" |
| 7721 | "Proxy-Authorization: NTLM "), |
| 7722 | MockWrite(negotiate_msg.c_str()), |
| 7723 | // End headers. |
| 7724 | MockWrite("\r\n\r\n"), |
| 7725 | |
| 7726 | // The second restart. |
| 7727 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7728 | "Host: origin:443\r\n" |
| 7729 | "Proxy-Connection: keep-alive\r\n" |
| 7730 | "Proxy-Authorization: NTLM "), |
| 7731 | MockWrite(authenticate_msg.c_str()), |
| 7732 | // End headers. |
| 7733 | MockWrite("\r\n\r\n"), |
| 7734 | }; |
| 7735 | |
| 7736 | MockRead data_reads[] = { |
| 7737 | // The initial NTLM response. |
| 7738 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7739 | "Content-Length: 0\r\n" |
| 7740 | "Proxy-Authenticate: NTLM\r\n\r\n"), |
| 7741 | |
| 7742 | // The NTLM challenge message. |
| 7743 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7744 | "Content-Length: 0\r\n" |
| 7745 | "Proxy-Authenticate: NTLM "), |
| 7746 | MockRead(challenge_msg.c_str()), |
| 7747 | // End headers. |
| 7748 | MockRead("\r\n\r\n"), |
| 7749 | |
| 7750 | // Finally the tunnel is established. |
| 7751 | MockRead("HTTP/1.1 200 Connected\r\n\r\n"), |
| 7752 | }; |
| 7753 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7754 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7755 | SSLSocketDataProvider data_ssl(ASYNC, ERR_CONNECTION_RESET); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7756 | StaticSocketDataProvider data2(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7757 | SSLSocketDataProvider data_ssl2(ASYNC, ERR_CONNECTION_RESET); |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 7758 | data_ssl2.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7759 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7760 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl); |
| 7761 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7762 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl2); |
| 7763 | |
| 7764 | // Start the transaction. The proxy responds with an NTLM authentication |
| 7765 | // request. |
| 7766 | TestCompletionCallback callback; |
| 7767 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7768 | int rv = callback.GetResult( |
| 7769 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 7770 | |
| 7771 | EXPECT_THAT(rv, IsOk()); |
| 7772 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7773 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7774 | ASSERT_TRUE(response); |
| 7775 | EXPECT_TRUE(CheckNTLMProxyAuth(response->auth_challenge.get())); |
| 7776 | |
| 7777 | // Configure credentials. The proxy responds with the challenge message. |
| 7778 | rv = callback.GetResult(trans.RestartWithAuth( |
| 7779 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7780 | callback.callback())); |
| 7781 | EXPECT_THAT(rv, IsOk()); |
| 7782 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7783 | response = trans.GetResponseInfo(); |
| 7784 | ASSERT_TRUE(response); |
| 7785 | EXPECT_FALSE(response->auth_challenge); |
| 7786 | |
| 7787 | // Restart once more. The tunnel will be established and the the SSL handshake |
| 7788 | // will reset. The TLS 1.3 version interference probe will then kick in and |
| 7789 | // restart the process. The proxy responds with another NTLM authentiation |
| 7790 | // request, but we don't need to provide credentials as the cached ones work/ |
| 7791 | rv = callback.GetResult( |
| 7792 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7793 | EXPECT_THAT(rv, IsOk()); |
| 7794 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7795 | response = trans.GetResponseInfo(); |
| 7796 | ASSERT_TRUE(response); |
| 7797 | EXPECT_FALSE(response->auth_challenge); |
| 7798 | |
| 7799 | // The proxy responds with the NTLM challenge message. |
| 7800 | rv = callback.GetResult( |
| 7801 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7802 | EXPECT_THAT(rv, IsOk()); |
| 7803 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7804 | response = trans.GetResponseInfo(); |
| 7805 | ASSERT_TRUE(response); |
| 7806 | EXPECT_FALSE(response->auth_challenge); |
| 7807 | |
| 7808 | // Send the NTLM authenticate message. The tunnel is established and the |
| 7809 | // handshake resets again. We should not retry again. |
| 7810 | rv = callback.GetResult( |
| 7811 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7812 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
| 7813 | } |
| 7814 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7815 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7816 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7817 | // Test reading a server response which has only headers, and no body. |
| 7818 | // After some maximum number of bytes is consumed, the transaction should |
| 7819 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7820 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7821 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7822 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7823 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7824 | request.traffic_annotation = |
| 7825 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7826 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7827 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7828 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7829 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7830 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 7831 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7832 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7833 | |
| 7834 | MockRead data_reads[] = { |
| 7835 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7836 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7837 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7838 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7839 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7840 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7841 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7842 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7843 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7844 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7845 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7846 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7847 | |
| 7848 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7849 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7850 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7851 | |
| 7852 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 7853 | // establish tunnel. |
| 7854 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7855 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7856 | HttpRequestInfo request; |
| 7857 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7858 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7859 | request.traffic_annotation = |
| 7860 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7861 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7862 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 7863 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 7864 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 7865 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7866 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7867 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7868 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7869 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7870 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7871 | // Since we have proxy, should try to establish tunnel. |
| 7872 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7873 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7874 | "Host: www.example.org:443\r\n" |
| 7875 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7876 | }; |
| 7877 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7878 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7879 | // connection. Usually a proxy would return 501 (not implemented), |
| 7880 | // or 200 (tunnel established). |
| 7881 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 7882 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7883 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7884 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7885 | }; |
| 7886 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7887 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7888 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7889 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7890 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7891 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7892 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7893 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7894 | |
| 7895 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7896 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7897 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7898 | // Empty the current queue. This is necessary because idle sockets are |
| 7899 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7900 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7901 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7902 | // We now check to make sure the TCPClientSocket was not added back to |
| 7903 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7904 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7905 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7906 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7907 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7908 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7909 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7910 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7911 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7912 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7913 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7914 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7915 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7916 | request.traffic_annotation = |
| 7917 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7918 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7919 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7920 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7921 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7922 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7923 | MockRead data_reads[] = { |
| 7924 | // A part of the response body is received with the response headers. |
| 7925 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7926 | // The rest of the response body is received in two parts. |
| 7927 | MockRead("lo"), |
| 7928 | MockRead(" world"), |
| 7929 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7930 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7931 | }; |
| 7932 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7933 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7934 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7935 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7936 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7937 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7938 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7939 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7940 | |
| 7941 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7942 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7943 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7944 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7945 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7946 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7947 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7948 | std::string status_line = response->headers->GetStatusLine(); |
| 7949 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7950 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7951 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7952 | |
| 7953 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7954 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7955 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7956 | EXPECT_EQ("hello world", response_data); |
| 7957 | |
| 7958 | // Empty the current queue. This is necessary because idle sockets are |
| 7959 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7960 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7961 | |
| 7962 | // 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] | 7963 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7964 | } |
| 7965 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7966 | // Make sure that we recycle a SSL socket after reading all of the response |
| 7967 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7968 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7969 | HttpRequestInfo request; |
| 7970 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7971 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7972 | request.traffic_annotation = |
| 7973 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7974 | |
| 7975 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7976 | MockWrite( |
| 7977 | "GET / HTTP/1.1\r\n" |
| 7978 | "Host: www.example.org\r\n" |
| 7979 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7980 | }; |
| 7981 | |
| 7982 | MockRead data_reads[] = { |
| 7983 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7984 | MockRead("Content-Length: 11\r\n\r\n"), |
| 7985 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7986 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7987 | }; |
| 7988 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7989 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7990 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7991 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7992 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7993 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7994 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7995 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7996 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7997 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7998 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7999 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8000 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8001 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8002 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8003 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8004 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8005 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8006 | ASSERT_TRUE(response); |
| 8007 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8008 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8009 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8010 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8011 | |
| 8012 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8013 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8014 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8015 | EXPECT_EQ("hello world", response_data); |
| 8016 | |
| 8017 | // Empty the current queue. This is necessary because idle sockets are |
| 8018 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8019 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8020 | |
| 8021 | // 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] | 8022 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8023 | } |
| 8024 | |
| 8025 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 8026 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8027 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8028 | HttpRequestInfo request; |
| 8029 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8030 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8031 | request.traffic_annotation = |
| 8032 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8033 | |
| 8034 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8035 | MockWrite( |
| 8036 | "GET / HTTP/1.1\r\n" |
| 8037 | "Host: www.example.org\r\n" |
| 8038 | "Connection: keep-alive\r\n\r\n"), |
| 8039 | MockWrite( |
| 8040 | "GET / HTTP/1.1\r\n" |
| 8041 | "Host: www.example.org\r\n" |
| 8042 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8043 | }; |
| 8044 | |
| 8045 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 8046 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8047 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8048 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8049 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8050 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8051 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8052 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8053 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8054 | StaticSocketDataProvider data(data_reads, data_writes); |
| 8055 | StaticSocketDataProvider data2(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8056 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8057 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8058 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8059 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8060 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8061 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8062 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8063 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8064 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8065 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8066 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8067 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8068 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8069 | |
| 8070 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8071 | ASSERT_TRUE(response); |
| 8072 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8073 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8074 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8075 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8076 | |
| 8077 | std::string response_data; |
| 8078 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8079 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8080 | EXPECT_EQ("hello world", response_data); |
| 8081 | |
| 8082 | // Empty the current queue. This is necessary because idle sockets are |
| 8083 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8084 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8085 | |
| 8086 | // 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] | 8087 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8088 | |
| 8089 | // Now start the second transaction, which should reuse the previous socket. |
| 8090 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8091 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8092 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8093 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8094 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8095 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8096 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8097 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8098 | |
| 8099 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8100 | ASSERT_TRUE(response); |
| 8101 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8102 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8103 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8104 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8105 | |
| 8106 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8107 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8108 | EXPECT_EQ("hello world", response_data); |
| 8109 | |
| 8110 | // Empty the current queue. This is necessary because idle sockets are |
| 8111 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8112 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8113 | |
| 8114 | // 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] | 8115 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8116 | } |
| 8117 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8118 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8119 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8120 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8121 | HttpRequestInfo request; |
| 8122 | request.method = "GET"; |
| 8123 | request.url = GURL("http://www.example.org/"); |
| 8124 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8125 | request.traffic_annotation = |
| 8126 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8127 | |
| 8128 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8129 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8130 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8131 | |
| 8132 | MockRead data_reads[] = { |
| 8133 | // A part of the response body is received with the response headers. |
| 8134 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8135 | // The rest of the response body is received in two parts. |
| 8136 | MockRead("lo"), MockRead(" world"), |
| 8137 | MockRead("junk"), // Should not be read!! |
| 8138 | MockRead(SYNCHRONOUS, OK), |
| 8139 | }; |
| 8140 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8141 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8142 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8143 | |
| 8144 | TestCompletionCallback callback; |
| 8145 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8146 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8147 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8148 | |
| 8149 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8150 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8151 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8152 | ASSERT_TRUE(response); |
| 8153 | EXPECT_TRUE(response->headers); |
| 8154 | std::string status_line = response->headers->GetStatusLine(); |
| 8155 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8156 | |
| 8157 | // Make memory critical notification and ensure the transaction still has been |
| 8158 | // operating right. |
| 8159 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8160 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8161 | base::RunLoop().RunUntilIdle(); |
| 8162 | |
| 8163 | // Socket should not be flushed as long as it is not idle. |
| 8164 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8165 | |
| 8166 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8167 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8168 | EXPECT_THAT(rv, IsOk()); |
| 8169 | EXPECT_EQ("hello world", response_data); |
| 8170 | |
| 8171 | // Empty the current queue. This is necessary because idle sockets are |
| 8172 | // added to the connection pool asynchronously with a PostTask. |
| 8173 | base::RunLoop().RunUntilIdle(); |
| 8174 | |
| 8175 | // We now check to make sure the socket was added back to the pool. |
| 8176 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8177 | |
| 8178 | // Idle sockets should be flushed now. |
| 8179 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8180 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8181 | base::RunLoop().RunUntilIdle(); |
| 8182 | |
| 8183 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8184 | } |
| 8185 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8186 | // Disable idle socket closing on memory pressure. |
| 8187 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8188 | // low memory notification and ensure the socket pool is NOT flushed. |
| 8189 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 8190 | HttpRequestInfo request; |
| 8191 | request.method = "GET"; |
| 8192 | request.url = GURL("http://www.example.org/"); |
| 8193 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8194 | request.traffic_annotation = |
| 8195 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8196 | |
| 8197 | // Disable idle socket closing on memory pressure. |
| 8198 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 8199 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8200 | |
| 8201 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 8202 | |
| 8203 | MockRead data_reads[] = { |
| 8204 | // A part of the response body is received with the response headers. |
| 8205 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8206 | // The rest of the response body is received in two parts. |
| 8207 | MockRead("lo"), MockRead(" world"), |
| 8208 | MockRead("junk"), // Should not be read!! |
| 8209 | MockRead(SYNCHRONOUS, OK), |
| 8210 | }; |
| 8211 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8212 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8213 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8214 | |
| 8215 | TestCompletionCallback callback; |
| 8216 | |
| 8217 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 8218 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8219 | |
| 8220 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8221 | |
| 8222 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 8223 | ASSERT_TRUE(response); |
| 8224 | EXPECT_TRUE(response->headers); |
| 8225 | std::string status_line = response->headers->GetStatusLine(); |
| 8226 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8227 | |
| 8228 | // Make memory critical notification and ensure the transaction still has been |
| 8229 | // operating right. |
| 8230 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8231 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8232 | base::RunLoop().RunUntilIdle(); |
| 8233 | |
| 8234 | // Socket should not be flushed as long as it is not idle. |
| 8235 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8236 | |
| 8237 | std::string response_data; |
| 8238 | rv = ReadTransaction(&trans, &response_data); |
| 8239 | EXPECT_THAT(rv, IsOk()); |
| 8240 | EXPECT_EQ("hello world", response_data); |
| 8241 | |
| 8242 | // Empty the current queue. This is necessary because idle sockets are |
| 8243 | // added to the connection pool asynchronously with a PostTask. |
| 8244 | base::RunLoop().RunUntilIdle(); |
| 8245 | |
| 8246 | // We now check to make sure the socket was added back to the pool. |
| 8247 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8248 | |
| 8249 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 8250 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8251 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 8252 | base::RunLoop().RunUntilIdle(); |
| 8253 | |
| 8254 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8255 | |
| 8256 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 8257 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8258 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8259 | base::RunLoop().RunUntilIdle(); |
| 8260 | |
| 8261 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8262 | } |
| 8263 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8264 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 8265 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8266 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8267 | HttpRequestInfo request; |
| 8268 | request.method = "GET"; |
| 8269 | request.url = GURL("https://www.example.org/"); |
| 8270 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8271 | request.traffic_annotation = |
| 8272 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8273 | |
| 8274 | MockWrite data_writes[] = { |
| 8275 | MockWrite("GET / HTTP/1.1\r\n" |
| 8276 | "Host: www.example.org\r\n" |
| 8277 | "Connection: keep-alive\r\n\r\n"), |
| 8278 | }; |
| 8279 | |
| 8280 | MockRead data_reads[] = { |
| 8281 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8282 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 8283 | |
| 8284 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8285 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8286 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8287 | StaticSocketDataProvider data(data_reads, data_writes); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8288 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8289 | |
| 8290 | TestCompletionCallback callback; |
| 8291 | |
| 8292 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8293 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8294 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8295 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8296 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8297 | |
| 8298 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8299 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8300 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8301 | ASSERT_TRUE(response); |
| 8302 | ASSERT_TRUE(response->headers); |
| 8303 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8304 | |
| 8305 | // Make memory critical notification and ensure the transaction still has been |
| 8306 | // operating right. |
| 8307 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8308 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8309 | base::RunLoop().RunUntilIdle(); |
| 8310 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8311 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8312 | |
| 8313 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8314 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8315 | EXPECT_THAT(rv, IsOk()); |
| 8316 | EXPECT_EQ("hello world", response_data); |
| 8317 | |
| 8318 | // Empty the current queue. This is necessary because idle sockets are |
| 8319 | // added to the connection pool asynchronously with a PostTask. |
| 8320 | base::RunLoop().RunUntilIdle(); |
| 8321 | |
| 8322 | // 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] | 8323 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8324 | |
| 8325 | // Make memory notification once again and ensure idle socket is closed. |
| 8326 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8327 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8328 | base::RunLoop().RunUntilIdle(); |
| 8329 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8330 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8331 | } |
| 8332 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8333 | // Make sure that we recycle a socket after a zero-length response. |
| 8334 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8335 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8336 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8337 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8338 | request.url = GURL( |
| 8339 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 8340 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 8341 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 8342 | "rt=prt.2642,ol.2649,xjs.2951"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8343 | request.traffic_annotation = |
| 8344 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8345 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8346 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8347 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8348 | MockRead data_reads[] = { |
| 8349 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 8350 | "Content-Length: 0\r\n" |
| 8351 | "Content-Type: text/html\r\n\r\n"), |
| 8352 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8353 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8354 | }; |
| 8355 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8356 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8357 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8358 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8359 | // Transaction must be created after the MockReads, so it's destroyed before |
| 8360 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8361 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8362 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8363 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8364 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8365 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8366 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8367 | |
| 8368 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8369 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8370 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8371 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8372 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8373 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8374 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8375 | std::string status_line = response->headers->GetStatusLine(); |
| 8376 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 8377 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8378 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8379 | |
| 8380 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8381 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8382 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8383 | EXPECT_EQ("", response_data); |
| 8384 | |
| 8385 | // Empty the current queue. This is necessary because idle sockets are |
| 8386 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8387 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8388 | |
| 8389 | // 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] | 8390 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8391 | } |
| 8392 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8393 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8394 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8395 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8396 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8397 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8398 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8399 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8400 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 8401 | // after use. |
| 8402 | request[0].method = "GET"; |
| 8403 | request[0].url = GURL("http://www.google.com/"); |
| 8404 | request[0].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8405 | request[0].traffic_annotation = |
| 8406 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8407 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 8408 | // transaction 1. The first attempts fails when writing the POST data. |
| 8409 | // This causes the transaction to retry with a new socket. The second |
| 8410 | // attempt succeeds. |
| 8411 | request[1].method = "POST"; |
| 8412 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8413 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8414 | request[1].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8415 | request[1].traffic_annotation = |
| 8416 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8417 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8418 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8419 | |
| 8420 | // The first socket is used for transaction 1 and the first attempt of |
| 8421 | // transaction 2. |
| 8422 | |
| 8423 | // The response of transaction 1. |
| 8424 | MockRead data_reads1[] = { |
| 8425 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 8426 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8427 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8428 | }; |
| 8429 | // The mock write results of transaction 1 and the first attempt of |
| 8430 | // transaction 2. |
| 8431 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8432 | MockWrite(SYNCHRONOUS, 64), // GET |
| 8433 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8434 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8435 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8436 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8437 | |
| 8438 | // The second socket is used for the second attempt of transaction 2. |
| 8439 | |
| 8440 | // The response of transaction 2. |
| 8441 | MockRead data_reads2[] = { |
| 8442 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 8443 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8444 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8445 | }; |
| 8446 | // The mock write results of the second attempt of transaction 2. |
| 8447 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8448 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8449 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8450 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8451 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8452 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8453 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8454 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8455 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8456 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8457 | "hello world", "welcome" |
| 8458 | }; |
| 8459 | |
| 8460 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8461 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8462 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8463 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8464 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8465 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8466 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8467 | |
| 8468 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8469 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8470 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8471 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8472 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8473 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8474 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8475 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8476 | |
| 8477 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8478 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8479 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8480 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 8481 | } |
| 8482 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8483 | |
| 8484 | // Test the request-challenge-retry sequence for basic auth when there is |
| 8485 | // 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] | 8486 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8487 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8488 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8489 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8490 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 8491 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8492 | request.traffic_annotation = |
| 8493 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8494 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8495 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8496 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8497 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8498 | // The password contains an escaped character -- for this test to pass it |
| 8499 | // will need to be unescaped by HttpNetworkTransaction. |
| 8500 | EXPECT_EQ("b%40r", request.url.password()); |
| 8501 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8502 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8503 | MockWrite( |
| 8504 | "GET / HTTP/1.1\r\n" |
| 8505 | "Host: www.example.org\r\n" |
| 8506 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8507 | }; |
| 8508 | |
| 8509 | MockRead data_reads1[] = { |
| 8510 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8511 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8512 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8513 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8514 | }; |
| 8515 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8516 | // After the challenge above, the transaction will be restarted using the |
| 8517 | // identity from the url (foo, b@r) to answer the challenge. |
| 8518 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8519 | MockWrite( |
| 8520 | "GET / HTTP/1.1\r\n" |
| 8521 | "Host: www.example.org\r\n" |
| 8522 | "Connection: keep-alive\r\n" |
| 8523 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8524 | }; |
| 8525 | |
| 8526 | MockRead data_reads2[] = { |
| 8527 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8528 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8529 | MockRead(SYNCHRONOUS, OK), |
| 8530 | }; |
| 8531 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8532 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8533 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8534 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8535 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8536 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8537 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8538 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8539 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8540 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8541 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8542 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8543 | |
| 8544 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8545 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8546 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8547 | rv = callback2.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_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8550 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8551 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8552 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8553 | |
| 8554 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8555 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8556 | |
| 8557 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8558 | |
| 8559 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8560 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8561 | } |
| 8562 | |
| 8563 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 8564 | // incorrect identity in the URL. The identity from the URL should be used only |
| 8565 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8566 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8567 | HttpRequestInfo request; |
| 8568 | request.method = "GET"; |
| 8569 | // Note: the URL has a username:password in it. The password "baz" is |
| 8570 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8571 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8572 | |
| 8573 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8574 | request.traffic_annotation = |
| 8575 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8576 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8577 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8578 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8579 | |
| 8580 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8581 | MockWrite( |
| 8582 | "GET / HTTP/1.1\r\n" |
| 8583 | "Host: www.example.org\r\n" |
| 8584 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8585 | }; |
| 8586 | |
| 8587 | MockRead data_reads1[] = { |
| 8588 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8589 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8590 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8591 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8592 | }; |
| 8593 | |
| 8594 | // After the challenge above, the transaction will be restarted using the |
| 8595 | // identity from the url (foo, baz) to answer the challenge. |
| 8596 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8597 | MockWrite( |
| 8598 | "GET / HTTP/1.1\r\n" |
| 8599 | "Host: www.example.org\r\n" |
| 8600 | "Connection: keep-alive\r\n" |
| 8601 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8602 | }; |
| 8603 | |
| 8604 | MockRead data_reads2[] = { |
| 8605 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8606 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8607 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8608 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8609 | }; |
| 8610 | |
| 8611 | // After the challenge above, the transaction will be restarted using the |
| 8612 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 8613 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8614 | MockWrite( |
| 8615 | "GET / HTTP/1.1\r\n" |
| 8616 | "Host: www.example.org\r\n" |
| 8617 | "Connection: keep-alive\r\n" |
| 8618 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8619 | }; |
| 8620 | |
| 8621 | MockRead data_reads3[] = { |
| 8622 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8623 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8624 | MockRead(SYNCHRONOUS, OK), |
| 8625 | }; |
| 8626 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8627 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8628 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 8629 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8630 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8631 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8632 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8633 | |
| 8634 | TestCompletionCallback callback1; |
| 8635 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8636 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8637 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8638 | |
| 8639 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8640 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8641 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8642 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8643 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8644 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8645 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8646 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8647 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8648 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8649 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8650 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8651 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8652 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 8653 | |
| 8654 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8655 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8656 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8657 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8658 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8659 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8660 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8661 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8662 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8663 | |
| 8664 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8665 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8666 | |
| 8667 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8668 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8669 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8670 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8671 | } |
| 8672 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8673 | |
| 8674 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 8675 | // correct identity in the URL, but its use is being suppressed. The identity |
| 8676 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8677 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8678 | HttpRequestInfo request; |
| 8679 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8680 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8681 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8682 | request.traffic_annotation = |
| 8683 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8684 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8685 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8686 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8687 | |
| 8688 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8689 | MockWrite( |
| 8690 | "GET / HTTP/1.1\r\n" |
| 8691 | "Host: www.example.org\r\n" |
| 8692 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8693 | }; |
| 8694 | |
| 8695 | MockRead data_reads1[] = { |
| 8696 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8697 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8698 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8699 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8700 | }; |
| 8701 | |
| 8702 | // After the challenge above, the transaction will be restarted using the |
| 8703 | // identity supplied by the user, not the one in the URL, to answer the |
| 8704 | // challenge. |
| 8705 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8706 | MockWrite( |
| 8707 | "GET / HTTP/1.1\r\n" |
| 8708 | "Host: www.example.org\r\n" |
| 8709 | "Connection: keep-alive\r\n" |
| 8710 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8711 | }; |
| 8712 | |
| 8713 | MockRead data_reads3[] = { |
| 8714 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8715 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8716 | MockRead(SYNCHRONOUS, OK), |
| 8717 | }; |
| 8718 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8719 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8720 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8721 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8722 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 8723 | |
| 8724 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8725 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8726 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8727 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8728 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8729 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8730 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8731 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8732 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8733 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 8734 | |
| 8735 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8736 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8737 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8738 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8739 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8740 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8741 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8742 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8743 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8744 | |
| 8745 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8746 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8747 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8748 | |
| 8749 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8750 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8751 | } |
| 8752 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8753 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8754 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8755 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8756 | |
| 8757 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8758 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8759 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8760 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8761 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8762 | request.traffic_annotation = |
| 8763 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8764 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8765 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8766 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8767 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8768 | MockWrite( |
| 8769 | "GET /x/y/z HTTP/1.1\r\n" |
| 8770 | "Host: www.example.org\r\n" |
| 8771 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8772 | }; |
| 8773 | |
| 8774 | MockRead data_reads1[] = { |
| 8775 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8776 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8777 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8778 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8779 | }; |
| 8780 | |
| 8781 | // Resend with authorization (username=foo, password=bar) |
| 8782 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8783 | MockWrite( |
| 8784 | "GET /x/y/z HTTP/1.1\r\n" |
| 8785 | "Host: www.example.org\r\n" |
| 8786 | "Connection: keep-alive\r\n" |
| 8787 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8788 | }; |
| 8789 | |
| 8790 | // Sever accepts the authorization. |
| 8791 | MockRead data_reads2[] = { |
| 8792 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8793 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8794 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8795 | }; |
| 8796 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8797 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8798 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8799 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8800 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8801 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8802 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8803 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8804 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8805 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8806 | |
| 8807 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8808 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8809 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8810 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8811 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8812 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8813 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8814 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8815 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8816 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8817 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8818 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8819 | |
| 8820 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8821 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8822 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8823 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8824 | ASSERT_TRUE(response); |
| 8825 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8826 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8827 | } |
| 8828 | |
| 8829 | // ------------------------------------------------------------------------ |
| 8830 | |
| 8831 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 8832 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8833 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8834 | request.method = "GET"; |
| 8835 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8836 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8837 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8838 | request.traffic_annotation = |
| 8839 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8840 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8841 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8842 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8843 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8844 | MockWrite( |
| 8845 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8846 | "Host: www.example.org\r\n" |
| 8847 | "Connection: keep-alive\r\n" |
| 8848 | // Send preemptive authorization for MyRealm1 |
| 8849 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8850 | }; |
| 8851 | |
| 8852 | // The server didn't like the preemptive authorization, and |
| 8853 | // challenges us for a different realm (MyRealm2). |
| 8854 | MockRead data_reads1[] = { |
| 8855 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8856 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 8857 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8858 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8859 | }; |
| 8860 | |
| 8861 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 8862 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8863 | MockWrite( |
| 8864 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8865 | "Host: www.example.org\r\n" |
| 8866 | "Connection: keep-alive\r\n" |
| 8867 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8868 | }; |
| 8869 | |
| 8870 | // Sever accepts the authorization. |
| 8871 | MockRead data_reads2[] = { |
| 8872 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8873 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8874 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8875 | }; |
| 8876 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8877 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8878 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8879 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8880 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8881 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8882 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8883 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8884 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8885 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8886 | |
| 8887 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8888 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8889 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8890 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8891 | ASSERT_TRUE(response); |
| 8892 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8893 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8894 | EXPECT_EQ("http://www.example.org", |
| 8895 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8896 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 8897 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8898 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8899 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8900 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8901 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 8902 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8903 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8904 | |
| 8905 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8906 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8907 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8908 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8909 | ASSERT_TRUE(response); |
| 8910 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8911 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8912 | } |
| 8913 | |
| 8914 | // ------------------------------------------------------------------------ |
| 8915 | |
| 8916 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 8917 | // succeed with preemptive authorization. |
| 8918 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8919 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8920 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8921 | request.url = GURL("http://www.example.org/x/y/z2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8922 | request.traffic_annotation = |
| 8923 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8924 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8925 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8926 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8927 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8928 | MockWrite( |
| 8929 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 8930 | "Host: www.example.org\r\n" |
| 8931 | "Connection: keep-alive\r\n" |
| 8932 | // The authorization for MyRealm1 gets sent preemptively |
| 8933 | // (since the url is in the same protection space) |
| 8934 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8935 | }; |
| 8936 | |
| 8937 | // Sever accepts the preemptive authorization |
| 8938 | MockRead data_reads1[] = { |
| 8939 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8940 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8941 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8942 | }; |
| 8943 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8944 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8945 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8946 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8947 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8948 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8949 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8950 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8951 | |
| 8952 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8953 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8954 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8955 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8956 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8957 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8958 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8959 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8960 | } |
| 8961 | |
| 8962 | // ------------------------------------------------------------------------ |
| 8963 | |
| 8964 | // Transaction 4: request another URL in MyRealm (however the |
| 8965 | // url is not known to belong to the protection space, so no pre-auth). |
| 8966 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8967 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8968 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8969 | request.url = GURL("http://www.example.org/x/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8970 | request.traffic_annotation = |
| 8971 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8972 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8973 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8974 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8975 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8976 | MockWrite( |
| 8977 | "GET /x/1 HTTP/1.1\r\n" |
| 8978 | "Host: www.example.org\r\n" |
| 8979 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8980 | }; |
| 8981 | |
| 8982 | MockRead data_reads1[] = { |
| 8983 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8984 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8985 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8986 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8987 | }; |
| 8988 | |
| 8989 | // Resend with authorization from MyRealm's cache. |
| 8990 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8991 | MockWrite( |
| 8992 | "GET /x/1 HTTP/1.1\r\n" |
| 8993 | "Host: www.example.org\r\n" |
| 8994 | "Connection: keep-alive\r\n" |
| 8995 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8996 | }; |
| 8997 | |
| 8998 | // Sever accepts the authorization. |
| 8999 | MockRead data_reads2[] = { |
| 9000 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9001 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9002 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9003 | }; |
| 9004 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9005 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9006 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9007 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9008 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9009 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9010 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9011 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9012 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9013 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9014 | |
| 9015 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9016 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9017 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9018 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9019 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9020 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9021 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9022 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9023 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9024 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9025 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9026 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9027 | ASSERT_TRUE(response); |
| 9028 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9029 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9030 | } |
| 9031 | |
| 9032 | // ------------------------------------------------------------------------ |
| 9033 | |
| 9034 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 9035 | // cached identity. Should invalidate and re-prompt. |
| 9036 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9037 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9038 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9039 | request.url = GURL("http://www.example.org/p/q/t"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9040 | request.traffic_annotation = |
| 9041 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9042 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9043 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9044 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9045 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9046 | MockWrite( |
| 9047 | "GET /p/q/t HTTP/1.1\r\n" |
| 9048 | "Host: www.example.org\r\n" |
| 9049 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9050 | }; |
| 9051 | |
| 9052 | MockRead data_reads1[] = { |
| 9053 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9054 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9055 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9056 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9057 | }; |
| 9058 | |
| 9059 | // Resend with authorization from cache for MyRealm. |
| 9060 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9061 | MockWrite( |
| 9062 | "GET /p/q/t HTTP/1.1\r\n" |
| 9063 | "Host: www.example.org\r\n" |
| 9064 | "Connection: keep-alive\r\n" |
| 9065 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9066 | }; |
| 9067 | |
| 9068 | // Sever rejects the authorization. |
| 9069 | MockRead data_reads2[] = { |
| 9070 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9071 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9072 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9073 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9074 | }; |
| 9075 | |
| 9076 | // At this point we should prompt for new credentials for MyRealm. |
| 9077 | // Restart with username=foo3, password=foo4. |
| 9078 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9079 | MockWrite( |
| 9080 | "GET /p/q/t HTTP/1.1\r\n" |
| 9081 | "Host: www.example.org\r\n" |
| 9082 | "Connection: keep-alive\r\n" |
| 9083 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9084 | }; |
| 9085 | |
| 9086 | // Sever accepts the authorization. |
| 9087 | MockRead data_reads3[] = { |
| 9088 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9089 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9090 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9091 | }; |
| 9092 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9093 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9094 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 9095 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9096 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9097 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9098 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9099 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9100 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9101 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9102 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9103 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9104 | |
| 9105 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9106 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9107 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9108 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9109 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9110 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9111 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9112 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9113 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9114 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9115 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9116 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9117 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9118 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9119 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9120 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9121 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9122 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 9123 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9124 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9125 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9126 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9127 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9128 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9129 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9130 | ASSERT_TRUE(response); |
| 9131 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9132 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9133 | } |
| 9134 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9135 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9136 | // Tests that nonce count increments when multiple auth attempts |
| 9137 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9138 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 9139 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 9140 | new HttpAuthHandlerDigest::Factory(); |
| 9141 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 9142 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 9143 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9144 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9145 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9146 | |
| 9147 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 9148 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9149 | HttpRequestInfo request; |
| 9150 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9151 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9152 | request.traffic_annotation = |
| 9153 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9154 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9155 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9156 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9157 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9158 | MockWrite( |
| 9159 | "GET /x/y/z HTTP/1.1\r\n" |
| 9160 | "Host: www.example.org\r\n" |
| 9161 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9162 | }; |
| 9163 | |
| 9164 | MockRead data_reads1[] = { |
| 9165 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9166 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 9167 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9168 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9169 | }; |
| 9170 | |
| 9171 | // Resend with authorization (username=foo, password=bar) |
| 9172 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9173 | MockWrite( |
| 9174 | "GET /x/y/z HTTP/1.1\r\n" |
| 9175 | "Host: www.example.org\r\n" |
| 9176 | "Connection: keep-alive\r\n" |
| 9177 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9178 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 9179 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 9180 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9181 | }; |
| 9182 | |
| 9183 | // Sever accepts the authorization. |
| 9184 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9185 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9186 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9187 | }; |
| 9188 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9189 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9190 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9191 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9192 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9193 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9194 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9195 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9196 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9197 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9198 | |
| 9199 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9200 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9201 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9202 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9203 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9204 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9205 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9206 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9207 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9208 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9209 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9210 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9211 | |
| 9212 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9213 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9214 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9215 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9216 | ASSERT_TRUE(response); |
| 9217 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9218 | } |
| 9219 | |
| 9220 | // ------------------------------------------------------------------------ |
| 9221 | |
| 9222 | // Transaction 2: Request another resource in digestive's protection space. |
| 9223 | // This will preemptively add an Authorization header which should have an |
| 9224 | // "nc" value of 2 (as compared to 1 in the first use. |
| 9225 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9226 | HttpRequestInfo request; |
| 9227 | request.method = "GET"; |
| 9228 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 9229 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9230 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9231 | request.traffic_annotation = |
| 9232 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9233 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9234 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9235 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9236 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9237 | MockWrite( |
| 9238 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 9239 | "Host: www.example.org\r\n" |
| 9240 | "Connection: keep-alive\r\n" |
| 9241 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9242 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 9243 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 9244 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9245 | }; |
| 9246 | |
| 9247 | // Sever accepts the authorization. |
| 9248 | MockRead data_reads1[] = { |
| 9249 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9250 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9251 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9252 | }; |
| 9253 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9254 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9255 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9256 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9257 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9258 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9259 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9260 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9261 | |
| 9262 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9263 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9264 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9265 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9266 | ASSERT_TRUE(response); |
| 9267 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9268 | } |
| 9269 | } |
| 9270 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9271 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9272 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9273 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9274 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9275 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9276 | |
| 9277 | // Setup some state (which we expect ResetStateForRestart() will clear). |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 9278 | trans.read_buf_ = base::MakeRefCounted<IOBuffer>(15); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9279 | trans.read_buf_len_ = 15; |
| 9280 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9281 | |
| 9282 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9283 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9284 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9285 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9286 | response->response_time = base::Time::Now(); |
| 9287 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9288 | |
| 9289 | { // Setup state for response_.vary_data |
| 9290 | HttpRequestInfo request; |
| 9291 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 9292 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 9293 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9294 | request.extra_headers.SetHeader("Foo", "1"); |
| 9295 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9296 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9297 | } |
| 9298 | |
| 9299 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9300 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9301 | |
| 9302 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9303 | EXPECT_FALSE(trans.read_buf_); |
| 9304 | EXPECT_EQ(0, trans.read_buf_len_); |
| 9305 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9306 | EXPECT_FALSE(response->auth_challenge); |
| 9307 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 9308 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9309 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9310 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9311 | } |
| 9312 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9313 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9314 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9315 | HttpRequestInfo request; |
| 9316 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9317 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9318 | request.traffic_annotation = |
| 9319 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9320 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9321 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9322 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9323 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9324 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9325 | MockWrite( |
| 9326 | "GET / HTTP/1.1\r\n" |
| 9327 | "Host: www.example.org\r\n" |
| 9328 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9329 | }; |
| 9330 | |
| 9331 | MockRead data_reads[] = { |
| 9332 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9333 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9334 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9335 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9336 | }; |
| 9337 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 9338 | StaticSocketDataProvider ssl_bad_certificate; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9339 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9340 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9341 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9342 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9343 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9344 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9345 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9346 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9347 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9348 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9349 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9350 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9351 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9352 | |
| 9353 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9354 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9355 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9356 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9357 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9358 | |
| 9359 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9360 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9361 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9362 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9363 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9364 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9365 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9366 | } |
| 9367 | |
| 9368 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 9369 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9370 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9371 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9372 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9373 | |
| 9374 | HttpRequestInfo request; |
| 9375 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9376 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9377 | request.traffic_annotation = |
| 9378 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9379 | |
| 9380 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9381 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9382 | "Host: www.example.org:443\r\n" |
| 9383 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9384 | }; |
| 9385 | |
| 9386 | MockRead proxy_reads[] = { |
| 9387 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9388 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9389 | }; |
| 9390 | |
| 9391 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9392 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9393 | "Host: www.example.org:443\r\n" |
| 9394 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9395 | MockWrite("GET / HTTP/1.1\r\n" |
| 9396 | "Host: www.example.org\r\n" |
| 9397 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9398 | }; |
| 9399 | |
| 9400 | MockRead data_reads[] = { |
| 9401 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9402 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9403 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9404 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9405 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9406 | }; |
| 9407 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9408 | StaticSocketDataProvider ssl_bad_certificate(proxy_reads, proxy_writes); |
| 9409 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9410 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9411 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9412 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9413 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9414 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9415 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9416 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9417 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9418 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9419 | |
| 9420 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9421 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9422 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9423 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9424 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9425 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9426 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9427 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9428 | |
| 9429 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9430 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9431 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9432 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9433 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9434 | |
| 9435 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9436 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9437 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9438 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9439 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9440 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9441 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9442 | } |
| 9443 | } |
| 9444 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9445 | |
| 9446 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9447 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9448 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9449 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9450 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9451 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9452 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9453 | |
| 9454 | HttpRequestInfo request; |
| 9455 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9456 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9457 | request.traffic_annotation = |
| 9458 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9459 | |
| 9460 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9461 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9462 | "Host: www.example.org:443\r\n" |
| 9463 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9464 | MockWrite("GET / HTTP/1.1\r\n" |
| 9465 | "Host: www.example.org\r\n" |
| 9466 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9467 | }; |
| 9468 | |
| 9469 | MockRead data_reads[] = { |
| 9470 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9471 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9472 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9473 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9474 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9475 | }; |
| 9476 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9477 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9478 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9479 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9480 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9481 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9482 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9483 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9484 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9485 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9486 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9487 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9488 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9489 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9490 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9491 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9492 | |
| 9493 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9494 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9495 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9496 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9497 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9498 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9499 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9500 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9501 | EXPECT_EQ(200, response->headers->response_code()); |
| 9502 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9503 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9504 | |
| 9505 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9506 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9507 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9508 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9509 | } |
| 9510 | |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9511 | // Test that an HTTPS Proxy can redirect a CONNECT request for main frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9512 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9513 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9514 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9515 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9516 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9517 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9518 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9519 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 9520 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 9521 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 9522 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9523 | HttpRequestInfo request; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9524 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9525 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9526 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9527 | request.traffic_annotation = |
| 9528 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9529 | |
| 9530 | MockWrite data_writes[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9531 | MockWrite(ASYNC, 0, |
| 9532 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9533 | "Host: www.example.org:443\r\n" |
| 9534 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9535 | }; |
| 9536 | |
| 9537 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9538 | // Pause on first read. |
| 9539 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 9540 | MockRead(ASYNC, 2, "HTTP/1.1 302 Redirect\r\n"), |
| 9541 | MockRead(ASYNC, 3, "Location: http://login.example.com/\r\n"), |
| 9542 | MockRead(ASYNC, 4, "Content-Length: 0\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9543 | }; |
| 9544 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9545 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9546 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9547 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9548 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9549 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9550 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9551 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9552 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9553 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9554 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9555 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9556 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9557 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9558 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
| 9559 | |
| 9560 | // Host resolution takes |kTimeIncrement|. |
| 9561 | FastForwardBy(kTimeIncrement); |
| 9562 | // Resolving the current request with |ResolveNow| will cause the pending |
| 9563 | // request to instantly complete, and the async connect will start as well. |
| 9564 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 9565 | |
| 9566 | // Connecting takes |kTimeIncrement|. |
| 9567 | FastForwardBy(kTimeIncrement); |
| 9568 | data.RunUntilPaused(); |
| 9569 | |
| 9570 | // The server takes |kTimeIncrement| to respond. |
| 9571 | FastForwardBy(kTimeIncrement); |
| 9572 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9573 | |
| 9574 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9575 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9576 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9577 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9578 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9579 | |
| 9580 | EXPECT_EQ(302, response->headers->response_code()); |
| 9581 | std::string url; |
| 9582 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 9583 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9584 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9585 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9586 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9587 | |
| 9588 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 9589 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9590 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9591 | // In the case of redirects from proxies, just as with all responses from |
| 9592 | // proxies, DNS and SSL times reflect timing to look up the destination's |
| 9593 | // name, and negotiate an SSL connection to it (Neither of which are done in |
| 9594 | // this case), which the DNS and SSL times for the proxy are all included in |
| 9595 | // connect_start / connect_end. See |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9596 | // HttpNetworkTransaction::OnHttpsProxyTunnelResponseRedirect |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9597 | |
| 9598 | EXPECT_TRUE(load_timing_info.connect_timing.dns_start.is_null()); |
| 9599 | EXPECT_TRUE(load_timing_info.connect_timing.dns_end.is_null()); |
| 9600 | EXPECT_TRUE(load_timing_info.connect_timing.ssl_start.is_null()); |
| 9601 | EXPECT_TRUE(load_timing_info.connect_timing.ssl_end.is_null()); |
| 9602 | |
| 9603 | EXPECT_EQ(start_time, load_timing_info.proxy_resolve_start); |
| 9604 | EXPECT_EQ(start_time, load_timing_info.proxy_resolve_end); |
| 9605 | EXPECT_EQ(start_time, load_timing_info.connect_timing.connect_start); |
| 9606 | EXPECT_EQ(start_time + 3 * kTimeIncrement, |
| 9607 | load_timing_info.connect_timing.connect_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9608 | |
| 9609 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 9610 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 9611 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9612 | } |
| 9613 | |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9614 | // Test that an HTTPS Proxy cannot redirect a CONNECT request for subresources. |
| 9615 | TEST_F(HttpNetworkTransactionTest, |
| 9616 | RedirectOfHttpsConnectSubresourceViaHttpsProxy) { |
| 9617 | base::HistogramTester histograms; |
| 9618 | session_deps_.proxy_resolution_service = |
| 9619 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9620 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9621 | TestNetLog net_log; |
| 9622 | session_deps_.net_log = &net_log; |
| 9623 | |
| 9624 | HttpRequestInfo request; |
| 9625 | request.method = "GET"; |
| 9626 | request.url = GURL("https://www.example.org/"); |
| 9627 | request.traffic_annotation = |
| 9628 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9629 | |
| 9630 | MockWrite data_writes[] = { |
| 9631 | MockWrite(ASYNC, 0, |
| 9632 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9633 | "Host: www.example.org:443\r\n" |
| 9634 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9635 | }; |
| 9636 | |
| 9637 | MockRead data_reads[] = { |
| 9638 | MockRead(ASYNC, 1, "HTTP/1.1 302 Redirect\r\n"), |
| 9639 | MockRead(ASYNC, 2, "Location: http://login.example.com/\r\n"), |
| 9640 | MockRead(ASYNC, 3, "Content-Length: 0\r\n\r\n"), |
| 9641 | }; |
| 9642 | |
| 9643 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
| 9644 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9645 | |
| 9646 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9647 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9648 | |
| 9649 | TestCompletionCallback callback; |
| 9650 | |
| 9651 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9652 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 9653 | |
| 9654 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 9655 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9656 | |
| 9657 | rv = callback.WaitForResult(); |
| 9658 | EXPECT_THAT(rv, IsError(ERR_HTTPS_PROXY_TUNNEL_RESPONSE_REDIRECT)); |
| 9659 | |
| 9660 | histograms.ExpectUniqueSample( |
| 9661 | "Net.Proxy.RedirectDuringConnect", |
| 9662 | HttpNetworkTransaction::kSubresourceByExplicitProxy, 1); |
| 9663 | } |
| 9664 | |
| 9665 | // Test that an HTTPS Proxy which was auto-detected cannot redirect a CONNECT |
| 9666 | // request for main frames. |
| 9667 | TEST_F(HttpNetworkTransactionTest, |
| 9668 | RedirectOfHttpsConnectViaAutoDetectedHttpsProxy) { |
| 9669 | base::HistogramTester histograms; |
| 9670 | session_deps_.proxy_resolution_service = |
| 9671 | ProxyResolutionService::CreateFixedFromAutoDetectedPacResult( |
| 9672 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9673 | TestNetLog net_log; |
| 9674 | session_deps_.net_log = &net_log; |
| 9675 | |
| 9676 | HttpRequestInfo request; |
| 9677 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
| 9678 | request.method = "GET"; |
| 9679 | request.url = GURL("https://www.example.org/"); |
| 9680 | request.traffic_annotation = |
| 9681 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9682 | |
| 9683 | MockWrite data_writes[] = { |
| 9684 | MockWrite(ASYNC, 0, |
| 9685 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9686 | "Host: www.example.org:443\r\n" |
| 9687 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9688 | }; |
| 9689 | |
| 9690 | MockRead data_reads[] = { |
| 9691 | MockRead(ASYNC, 1, "HTTP/1.1 302 Redirect\r\n"), |
| 9692 | MockRead(ASYNC, 2, "Location: http://login.example.com/\r\n"), |
| 9693 | MockRead(ASYNC, 3, "Content-Length: 0\r\n\r\n"), |
| 9694 | }; |
| 9695 | |
| 9696 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
| 9697 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9698 | |
| 9699 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9700 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9701 | |
| 9702 | TestCompletionCallback callback; |
| 9703 | |
| 9704 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 9705 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 9706 | |
| 9707 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 9708 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 9709 | |
| 9710 | rv = callback.WaitForResult(); |
| 9711 | EXPECT_THAT(rv, IsError(ERR_HTTPS_PROXY_TUNNEL_RESPONSE_REDIRECT)); |
| 9712 | |
| 9713 | histograms.ExpectUniqueSample( |
| 9714 | "Net.Proxy.RedirectDuringConnect", |
| 9715 | HttpNetworkTransaction::kMainFrameByAutoDetectedProxy, 1); |
| 9716 | } |
| 9717 | |
| 9718 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request for main |
| 9719 | // frames. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9720 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9721 | base::HistogramTester histograms; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9722 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9723 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9724 | TestNetLog net_log; |
| 9725 | session_deps_.net_log = &net_log; |
| 9726 | |
| 9727 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 9728 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 9729 | session_deps_.host_resolver->set_ondemand_mode(true); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9730 | |
| 9731 | HttpRequestInfo request; |
| 9732 | request.method = "GET"; |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9733 | request.load_flags = LOAD_MAIN_FRAME_DEPRECATED; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9734 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9735 | request.traffic_annotation = |
| 9736 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9737 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9738 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 9739 | nullptr, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9740 | spdy::SpdySerializedFrame goaway( |
| 9741 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9742 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9743 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9744 | CreateMockWrite(goaway, 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9745 | }; |
| 9746 | |
| 9747 | static const char* const kExtraHeaders[] = { |
| 9748 | "location", |
| 9749 | "http://login.example.com/", |
| 9750 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9751 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9752 | "302", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9753 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9754 | // Pause on first read. |
| 9755 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp, 2), |
| 9756 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9757 | }; |
| 9758 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9759 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9760 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9761 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9762 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9763 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9764 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9765 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9766 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9767 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9768 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9769 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9770 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9771 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9772 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9773 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9774 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9775 | // Host resolution takes |kTimeIncrement|. |
| 9776 | FastForwardBy(kTimeIncrement); |
| 9777 | // Resolving the current request with |ResolveNow| will cause the pending |
| 9778 | // request to instantly complete, and the async connect will start as well. |
| 9779 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 9780 | |
| 9781 | // Connecting takes |kTimeIncrement|. |
| 9782 | FastForwardBy(kTimeIncrement); |
| 9783 | data.RunUntilPaused(); |
| 9784 | |
| 9785 | FastForwardBy(kTimeIncrement); |
| 9786 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9787 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9788 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9789 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9790 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9791 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9792 | |
| 9793 | EXPECT_EQ(302, response->headers->response_code()); |
| 9794 | std::string url; |
| 9795 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 9796 | EXPECT_EQ("http://login.example.com/", url); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9797 | |
| 9798 | LoadTimingInfo load_timing_info; |
| 9799 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 9800 | |
| 9801 | EXPECT_FALSE(load_timing_info.socket_reused); |
| 9802 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
| 9803 | |
| 9804 | // No proxy resolution times, since there's no PAC script. |
| 9805 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 9806 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 9807 | |
| 9808 | // In the case of redirects from proxies, just as with all responses from |
| 9809 | // proxies, DNS and SSL times reflect timing to look up the destination's |
| 9810 | // name, and negotiate an SSL connection to it (Neither of which are done in |
| 9811 | // this case), which the DNS and SSL times for the proxy are all included in |
| 9812 | // connect_start / connect_end. See |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9813 | // HttpNetworkTransaction::OnHttpsProxyTunnelResponseRedirect. |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9814 | |
| 9815 | EXPECT_TRUE(load_timing_info.connect_timing.dns_start.is_null()); |
| 9816 | EXPECT_TRUE(load_timing_info.connect_timing.dns_end.is_null()); |
| 9817 | EXPECT_TRUE(load_timing_info.connect_timing.ssl_start.is_null()); |
| 9818 | EXPECT_TRUE(load_timing_info.connect_timing.ssl_end.is_null()); |
| 9819 | |
| 9820 | EXPECT_EQ(start_time, load_timing_info.connect_timing.connect_start); |
| 9821 | EXPECT_EQ(start_time + 3 * kTimeIncrement, |
| 9822 | load_timing_info.connect_timing.connect_end); |
| 9823 | |
| 9824 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 9825 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 9826 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
Eric Roman | 74103c7 | 2019-02-21 00:23:12 | [diff] [blame] | 9827 | |
| 9828 | histograms.ExpectUniqueSample( |
| 9829 | "Net.Proxy.RedirectDuringConnect", |
| 9830 | HttpNetworkTransaction::kMainFrameByExplicitProxy, 1); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9831 | } |
| 9832 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9833 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9834 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9835 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9836 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9837 | |
| 9838 | HttpRequestInfo request; |
| 9839 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9840 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9841 | request.traffic_annotation = |
| 9842 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9843 | |
| 9844 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9845 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9846 | "Host: www.example.org:443\r\n" |
| 9847 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9848 | }; |
| 9849 | |
| 9850 | MockRead data_reads[] = { |
| 9851 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 9852 | MockRead("Content-Length: 23\r\n\r\n"), |
| 9853 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9854 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9855 | }; |
| 9856 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9857 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9858 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9859 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9860 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9861 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9862 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9863 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9864 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9865 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9866 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9867 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9868 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9869 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9870 | |
| 9871 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9872 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9873 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9874 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9875 | } |
| 9876 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9877 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9878 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9879 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9880 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9881 | |
| 9882 | HttpRequestInfo request; |
| 9883 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9884 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9885 | request.traffic_annotation = |
| 9886 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9887 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9888 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 9889 | nullptr, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9890 | spdy::SpdySerializedFrame rst( |
| 9891 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9892 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9893 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9894 | }; |
| 9895 | |
| 9896 | static const char* const kExtraHeaders[] = { |
| 9897 | "location", |
| 9898 | "http://login.example.com/", |
| 9899 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9900 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9901 | "404", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9902 | spdy::SpdySerializedFrame body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9903 | spdy_util_.ConstructSpdyDataFrame(1, "The host does not exist", true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9904 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9905 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9906 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9907 | }; |
| 9908 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9909 | SequencedSocketData data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9910 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9911 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9912 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9913 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9914 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9915 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9916 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9917 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9918 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9919 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9920 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9921 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9922 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9923 | |
| 9924 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9925 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9926 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9927 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9928 | } |
| 9929 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9930 | // Test the request-challenge-retry sequence for basic auth, through |
| 9931 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9932 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9933 | HttpRequestInfo request; |
| 9934 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9935 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9936 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 9937 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9938 | request.traffic_annotation = |
| 9939 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9940 | |
| 9941 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9942 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9943 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9944 | "HTTPS myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9945 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9946 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9947 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9948 | |
| 9949 | // Since we have proxy, should try to establish tunnel. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9950 | spdy::SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 9951 | nullptr, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9952 | spdy::SpdySerializedFrame rst( |
| 9953 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9954 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9955 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9956 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9957 | // be issuing -- the final header line contains the credentials. |
| 9958 | const char* const kAuthCredentials[] = { |
| 9959 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 9960 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9961 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9962 | kAuthCredentials, base::size(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9963 | HostPortPair("www.example.org", 443))); |
| 9964 | // fetch https://www.example.org/ via HTTP |
| 9965 | const char get[] = |
| 9966 | "GET / HTTP/1.1\r\n" |
| 9967 | "Host: www.example.org\r\n" |
| 9968 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9969 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9970 | spdy_util_.ConstructSpdyDataFrame(3, get, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9971 | |
| 9972 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9973 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 9974 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9975 | }; |
| 9976 | |
| 9977 | // The proxy responds to the connect with a 407, using a persistent |
| 9978 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 9979 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9980 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9981 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 9982 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9983 | spdy::SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9984 | kAuthStatus, kAuthChallenge, base::size(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9985 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9986 | spdy::SpdySerializedFrame conn_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 9987 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9988 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 9989 | "Content-Length: 5\r\n\r\n"; |
| 9990 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9991 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9992 | spdy_util_.ConstructSpdyDataFrame(3, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9993 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9994 | spdy_util_.ConstructSpdyDataFrame(3, "hello", false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9995 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9996 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 9997 | CreateMockRead(conn_resp, 4, ASYNC), |
| 9998 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 9999 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 10000 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10001 | }; |
| 10002 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10003 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10004 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10005 | // Negotiate SPDY to the proxy |
| 10006 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10007 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10008 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10009 | // Vanilla SSL to the server |
| 10010 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10011 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10012 | |
| 10013 | TestCompletionCallback callback1; |
| 10014 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10015 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10016 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10017 | |
| 10018 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10019 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10020 | |
| 10021 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10022 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 10023 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10024 | log.GetEntries(&entries); |
| 10025 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 10026 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 10027 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10028 | ExpectLogContainsSomewhere( |
| 10029 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 10030 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 10031 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10032 | |
| 10033 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10034 | ASSERT_TRUE(response); |
| 10035 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10036 | EXPECT_EQ(407, response->headers->response_code()); |
| 10037 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10038 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10039 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10040 | |
| 10041 | TestCompletionCallback callback2; |
| 10042 | |
| 10043 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 10044 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10045 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10046 | |
| 10047 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10048 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10049 | |
| 10050 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10051 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10052 | |
| 10053 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10054 | EXPECT_EQ(200, response->headers->response_code()); |
| 10055 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 10056 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10057 | |
| 10058 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10059 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10060 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10061 | LoadTimingInfo load_timing_info; |
| 10062 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10063 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10064 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10065 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 10066 | trans.reset(); |
| 10067 | session->CloseAllConnections(); |
| 10068 | } |
| 10069 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10070 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 10071 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10072 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10073 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10074 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10075 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 10076 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10077 | HttpRequestInfo request; |
| 10078 | HttpRequestInfo push_request; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10079 | request.traffic_annotation = |
| 10080 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10081 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10082 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10083 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10084 | push_request.method = "GET"; |
| 10085 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10086 | push_request.traffic_annotation = |
| 10087 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10088 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10089 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10090 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10091 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10092 | "HTTPS myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10093 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10094 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10095 | |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10096 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10097 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10098 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10099 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10100 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10101 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10102 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10103 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10104 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10105 | |
| 10106 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10107 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10108 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10109 | }; |
| 10110 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10111 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 10112 | nullptr, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 10113 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10114 | spdy::SpdySerializedFrame stream1_reply( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 10115 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10116 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10117 | spdy::SpdySerializedFrame stream1_body( |
| 10118 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10119 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10120 | spdy::SpdySerializedFrame stream2_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 10121 | spdy_util_.ConstructSpdyDataFrame(2, "pushed", true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10122 | |
| 10123 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 10124 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 10125 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10126 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10127 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10128 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10129 | }; |
| 10130 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10131 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10132 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10133 | // Negotiate SPDY to the proxy |
| 10134 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10135 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10136 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10137 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10138 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10139 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10140 | TestCompletionCallback callback; |
| 10141 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10142 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10143 | |
| 10144 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10145 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10146 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10147 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10148 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10149 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10150 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10151 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10152 | |
| 10153 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10154 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10155 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 10156 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10157 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10158 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10159 | |
| 10160 | EXPECT_EQ(200, response->headers->response_code()); |
| 10161 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10162 | |
| 10163 | std::string response_data; |
| 10164 | rv = ReadTransaction(trans.get(), &response_data); |
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 | EXPECT_EQ("hello!", response_data); |
| 10167 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10168 | LoadTimingInfo load_timing_info; |
| 10169 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10170 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10171 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10172 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10173 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10174 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10175 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 10176 | |
| 10177 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10178 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10179 | EXPECT_EQ("pushed", response_data); |
| 10180 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10181 | LoadTimingInfo push_load_timing_info; |
| 10182 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 10183 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 10184 | // The transactions should share a socket ID, despite being for different |
| 10185 | // origins. |
| 10186 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 10187 | push_load_timing_info.socket_log_id); |
| 10188 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10189 | trans.reset(); |
| 10190 | push_trans.reset(); |
| 10191 | session->CloseAllConnections(); |
| 10192 | } |
| 10193 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10194 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10195 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10196 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10197 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10198 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 10199 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10200 | HttpRequestInfo request; |
| 10201 | |
| 10202 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10203 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10204 | request.traffic_annotation = |
| 10205 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10206 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10207 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10208 | "https://myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10209 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10210 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10211 | |
| 10212 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10213 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10214 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10215 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10216 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10217 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10218 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10219 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10220 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10221 | spdy::SpdySerializedFrame push_rst( |
| 10222 | spdy_util_.ConstructSpdyRstStream(2, spdy::ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10223 | |
| 10224 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10225 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10226 | }; |
| 10227 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10228 | spdy::SpdySerializedFrame stream1_reply( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 10229 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10230 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10231 | spdy::SpdySerializedFrame stream1_body( |
| 10232 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10233 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10234 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 10235 | nullptr, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10236 | |
| 10237 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10238 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10239 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 10240 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 10241 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10242 | }; |
| 10243 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10244 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10245 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10246 | // Negotiate SPDY to the proxy |
| 10247 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10248 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10249 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10250 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10251 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10252 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10253 | TestCompletionCallback callback; |
| 10254 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10255 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10256 | |
| 10257 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10258 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10259 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10260 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10261 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10262 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10263 | |
| 10264 | EXPECT_EQ(200, response->headers->response_code()); |
| 10265 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10266 | |
| 10267 | std::string response_data; |
| 10268 | rv = ReadTransaction(trans.get(), &response_data); |
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 | EXPECT_EQ("hello!", response_data); |
| 10271 | |
| 10272 | trans.reset(); |
| 10273 | session->CloseAllConnections(); |
| 10274 | } |
| 10275 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10276 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 10277 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10278 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10279 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10280 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10281 | proxy_delegate->set_trusted_spdy_proxy( |
| 10282 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 10283 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10284 | HttpRequestInfo request; |
| 10285 | |
| 10286 | request.method = "GET"; |
| 10287 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10288 | request.traffic_annotation = |
| 10289 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10290 | |
| 10291 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10292 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10293 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10294 | BoundTestNetLog log; |
| 10295 | session_deps_.net_log = log.bound().net_log(); |
| 10296 | |
| 10297 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10298 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10299 | proxy_delegate.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10300 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10301 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10302 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10303 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10304 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10305 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10306 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10307 | |
| 10308 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10309 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10310 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10311 | }; |
| 10312 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10313 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10314 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10315 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10316 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 10317 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 10318 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10319 | spdy::SpdySerializedFrame stream1_body( |
| 10320 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10321 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10322 | spdy::SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10323 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10324 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10325 | spdy::SpdySerializedFrame stream2_body( |
| 10326 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10327 | |
| 10328 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10329 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10330 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10331 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10332 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10333 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10334 | }; |
| 10335 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10336 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10337 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 10338 | // Negotiate SPDY to the proxy |
| 10339 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10340 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10341 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 10342 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10343 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10344 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10345 | TestCompletionCallback callback; |
| 10346 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10347 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10348 | |
| 10349 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10350 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10351 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10352 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10353 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10354 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10355 | |
| 10356 | EXPECT_EQ(200, response->headers->response_code()); |
| 10357 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10358 | |
| 10359 | std::string response_data; |
| 10360 | rv = ReadTransaction(trans.get(), &response_data); |
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 | EXPECT_EQ("hello!", response_data); |
| 10363 | |
| 10364 | trans.reset(); |
| 10365 | session->CloseAllConnections(); |
| 10366 | } |
| 10367 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10368 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 10369 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10370 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10371 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10372 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10373 | |
| 10374 | HttpRequestInfo request; |
| 10375 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10376 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10377 | request.traffic_annotation = |
| 10378 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10379 | |
| 10380 | // Attempt to fetch the URL from a server with a bad cert |
| 10381 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10382 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10383 | "Host: www.example.org:443\r\n" |
| 10384 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10385 | }; |
| 10386 | |
| 10387 | MockRead bad_cert_reads[] = { |
| 10388 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10389 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10390 | }; |
| 10391 | |
| 10392 | // Attempt to fetch the URL with a good cert |
| 10393 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10394 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10395 | "Host: www.example.org:443\r\n" |
| 10396 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10397 | MockWrite("GET / HTTP/1.1\r\n" |
| 10398 | "Host: www.example.org\r\n" |
| 10399 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10400 | }; |
| 10401 | |
| 10402 | MockRead good_cert_reads[] = { |
| 10403 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 10404 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10405 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10406 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10407 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10408 | }; |
| 10409 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10410 | StaticSocketDataProvider ssl_bad_certificate(bad_cert_reads, bad_cert_writes); |
| 10411 | StaticSocketDataProvider data(good_cert_reads, good_data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10412 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 10413 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10414 | |
| 10415 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10416 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10417 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 10418 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10419 | |
| 10420 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10421 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10422 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10423 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10424 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10425 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10426 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10427 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10428 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10429 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10430 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10431 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10432 | |
| 10433 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10434 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10435 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10436 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10437 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10438 | |
| 10439 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10440 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10441 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10442 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10443 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10444 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10445 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10446 | } |
| 10447 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10448 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10449 | HttpRequestInfo request; |
| 10450 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10451 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10452 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10453 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10454 | request.traffic_annotation = |
| 10455 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10456 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10457 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10458 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10459 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10460 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10461 | MockWrite( |
| 10462 | "GET / HTTP/1.1\r\n" |
| 10463 | "Host: www.example.org\r\n" |
| 10464 | "Connection: keep-alive\r\n" |
| 10465 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10466 | }; |
| 10467 | |
| 10468 | // Lastly, the server responds with the actual content. |
| 10469 | MockRead data_reads[] = { |
| 10470 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10471 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10472 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10473 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10474 | }; |
| 10475 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10476 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10477 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10478 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10479 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10480 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10481 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10482 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10483 | |
| 10484 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10485 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10486 | } |
| 10487 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10488 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10489 | // Test user agent values, used both for the request header of the original |
| 10490 | // request, and the value returned by the HttpUserAgentSettings. nullptr means |
| 10491 | // no request header / no HttpUserAgentSettings object. |
| 10492 | const char* kTestUserAgents[] = {nullptr, "", "Foopy"}; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10493 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10494 | for (const char* setting_user_agent : kTestUserAgents) { |
| 10495 | if (!setting_user_agent) { |
| 10496 | session_deps_.http_user_agent_settings.reset(); |
| 10497 | } else { |
| 10498 | session_deps_.http_user_agent_settings = |
| 10499 | std::make_unique<StaticHttpUserAgentSettings>( |
| 10500 | std::string() /* accept-language */, setting_user_agent); |
| 10501 | } |
| 10502 | session_deps_.proxy_resolution_service = |
| 10503 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 10504 | TRAFFIC_ANNOTATION_FOR_TESTS); |
| 10505 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 10506 | for (const char* request_user_agent : kTestUserAgents) { |
| 10507 | HttpRequestInfo request; |
| 10508 | request.method = "GET"; |
| 10509 | request.url = GURL("https://www.example.org/"); |
| 10510 | if (request_user_agent) { |
| 10511 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10512 | request_user_agent); |
| 10513 | } |
| 10514 | request.traffic_annotation = |
| 10515 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10516 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10517 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10518 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10519 | std::string expected_request; |
| 10520 | if (!setting_user_agent || strlen(setting_user_agent) == 0) { |
| 10521 | expected_request = |
| 10522 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10523 | "Host: www.example.org:443\r\n" |
| 10524 | "Proxy-Connection: keep-alive\r\n\r\n"; |
| 10525 | } else { |
| 10526 | expected_request = base::StringPrintf( |
| 10527 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10528 | "Host: www.example.org:443\r\n" |
| 10529 | "Proxy-Connection: keep-alive\r\n" |
| 10530 | "User-Agent: %s\r\n\r\n", |
| 10531 | setting_user_agent); |
| 10532 | } |
| 10533 | MockWrite data_writes[] = { |
| 10534 | MockWrite(expected_request.c_str()), |
| 10535 | }; |
| 10536 | MockRead data_reads[] = { |
| 10537 | // Return an error, so the transaction stops here (this test isn't |
| 10538 | // interested in the rest). |
| 10539 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 10540 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10541 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 10542 | }; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10543 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10544 | StaticSocketDataProvider data(data_reads, data_writes); |
| 10545 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10546 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10547 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10548 | |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 10549 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 10550 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 10551 | |
| 10552 | rv = callback.WaitForResult(); |
| 10553 | EXPECT_THAT(rv, IsOk()); |
| 10554 | } |
| 10555 | } |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10556 | } |
| 10557 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10558 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10559 | HttpRequestInfo request; |
| 10560 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10561 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 10562 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 10563 | "http://the.previous.site.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10564 | request.traffic_annotation = |
| 10565 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10566 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10567 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10568 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10569 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10570 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10571 | MockWrite( |
| 10572 | "GET / HTTP/1.1\r\n" |
| 10573 | "Host: www.example.org\r\n" |
| 10574 | "Connection: keep-alive\r\n" |
| 10575 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10576 | }; |
| 10577 | |
| 10578 | // Lastly, the server responds with the actual content. |
| 10579 | MockRead data_reads[] = { |
| 10580 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10581 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10582 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10583 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10584 | }; |
| 10585 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10586 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10587 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10588 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10589 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10590 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10591 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10592 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10593 | |
| 10594 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10595 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10596 | } |
| 10597 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10598 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10599 | HttpRequestInfo request; |
| 10600 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10601 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10602 | request.traffic_annotation = |
| 10603 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10604 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10605 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10606 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10607 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10608 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10609 | MockWrite( |
| 10610 | "POST / HTTP/1.1\r\n" |
| 10611 | "Host: www.example.org\r\n" |
| 10612 | "Connection: keep-alive\r\n" |
| 10613 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10614 | }; |
| 10615 | |
| 10616 | // Lastly, the server responds with the actual content. |
| 10617 | MockRead data_reads[] = { |
| 10618 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10619 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10620 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10621 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10622 | }; |
| 10623 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10624 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10625 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10626 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10627 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10628 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10629 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10630 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10631 | |
| 10632 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10633 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10634 | } |
| 10635 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10636 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10637 | HttpRequestInfo request; |
| 10638 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10639 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10640 | request.traffic_annotation = |
| 10641 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10642 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10643 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10644 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10645 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10646 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10647 | MockWrite( |
| 10648 | "PUT / HTTP/1.1\r\n" |
| 10649 | "Host: www.example.org\r\n" |
| 10650 | "Connection: keep-alive\r\n" |
| 10651 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10652 | }; |
| 10653 | |
| 10654 | // Lastly, the server responds with the actual content. |
| 10655 | MockRead data_reads[] = { |
| 10656 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10657 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10658 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10659 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10660 | }; |
| 10661 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10662 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10663 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10664 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10665 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10666 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10667 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10668 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10669 | |
| 10670 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10671 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10672 | } |
| 10673 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10674 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10675 | HttpRequestInfo request; |
| 10676 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10677 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10678 | request.traffic_annotation = |
| 10679 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10680 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10681 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10682 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10683 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10684 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 10685 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 10686 | "Host: www.example.org\r\n" |
| 10687 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10688 | }; |
| 10689 | |
| 10690 | // Lastly, the server responds with the actual content. |
| 10691 | MockRead data_reads[] = { |
| 10692 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10693 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10694 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10695 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10696 | }; |
| 10697 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10698 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10699 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10700 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10701 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10702 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10703 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10704 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10705 | |
| 10706 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10707 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10708 | } |
| 10709 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10710 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10711 | HttpRequestInfo request; |
| 10712 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10713 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10714 | request.load_flags = LOAD_BYPASS_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10715 | request.traffic_annotation = |
| 10716 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10717 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10718 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10719 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10720 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10721 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10722 | MockWrite( |
| 10723 | "GET / HTTP/1.1\r\n" |
| 10724 | "Host: www.example.org\r\n" |
| 10725 | "Connection: keep-alive\r\n" |
| 10726 | "Pragma: no-cache\r\n" |
| 10727 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10728 | }; |
| 10729 | |
| 10730 | // Lastly, the server responds with the actual content. |
| 10731 | MockRead data_reads[] = { |
| 10732 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10733 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10734 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10735 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10736 | }; |
| 10737 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10738 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10739 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10740 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10741 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10742 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10743 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10744 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10745 | |
| 10746 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10747 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10748 | } |
| 10749 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10750 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10751 | HttpRequestInfo request; |
| 10752 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10753 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10754 | request.load_flags = LOAD_VALIDATE_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10755 | request.traffic_annotation = |
| 10756 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10757 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10758 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10759 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10760 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10761 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10762 | MockWrite( |
| 10763 | "GET / HTTP/1.1\r\n" |
| 10764 | "Host: www.example.org\r\n" |
| 10765 | "Connection: keep-alive\r\n" |
| 10766 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10767 | }; |
| 10768 | |
| 10769 | // Lastly, the server responds with the actual content. |
| 10770 | MockRead data_reads[] = { |
| 10771 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10772 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10773 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10774 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10775 | }; |
| 10776 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10777 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10778 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10779 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10780 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10781 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10782 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10783 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10784 | |
| 10785 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10786 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10787 | } |
| 10788 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10789 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10790 | HttpRequestInfo request; |
| 10791 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10792 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10793 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10794 | request.traffic_annotation = |
| 10795 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10796 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10797 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10798 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10799 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10800 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10801 | MockWrite( |
| 10802 | "GET / HTTP/1.1\r\n" |
| 10803 | "Host: www.example.org\r\n" |
| 10804 | "Connection: keep-alive\r\n" |
| 10805 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10806 | }; |
| 10807 | |
| 10808 | // Lastly, the server responds with the actual content. |
| 10809 | MockRead data_reads[] = { |
| 10810 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10811 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10812 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10813 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10814 | }; |
| 10815 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10816 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10817 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10818 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10819 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10820 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10821 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10822 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10823 | |
| 10824 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10825 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10826 | } |
| 10827 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10828 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10829 | HttpRequestInfo request; |
| 10830 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10831 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10832 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 10833 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 10834 | request.extra_headers.SetHeader("FoO", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10835 | request.traffic_annotation = |
| 10836 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10837 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10838 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10839 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10840 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10841 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10842 | MockWrite( |
| 10843 | "GET / HTTP/1.1\r\n" |
| 10844 | "Host: www.example.org\r\n" |
| 10845 | "Connection: keep-alive\r\n" |
| 10846 | "referer: www.foo.com\r\n" |
| 10847 | "hEllo: Kitty\r\n" |
| 10848 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10849 | }; |
| 10850 | |
| 10851 | // Lastly, the server responds with the actual content. |
| 10852 | MockRead data_reads[] = { |
| 10853 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10854 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10855 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10856 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10857 | }; |
| 10858 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10859 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10860 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10861 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10862 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10863 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10864 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10865 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10866 | |
| 10867 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10868 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10869 | } |
| 10870 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10871 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10872 | HttpRequestInfo request; |
| 10873 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10874 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10875 | request.traffic_annotation = |
| 10876 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10877 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10878 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10879 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10880 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10881 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10882 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10883 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10884 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10885 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10886 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10887 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 10888 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10889 | |
| 10890 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10891 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 10892 | MockWrite("GET / HTTP/1.1\r\n" |
| 10893 | "Host: www.example.org\r\n" |
| 10894 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10895 | |
| 10896 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10897 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 10898 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10899 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10900 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10901 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10902 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10903 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10904 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10905 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10906 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10907 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10908 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10909 | |
| 10910 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10911 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10912 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10913 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10914 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10915 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10916 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10917 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10918 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10919 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10920 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10921 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10922 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10923 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10924 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10925 | EXPECT_EQ("Payload", response_text); |
| 10926 | } |
| 10927 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10928 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10929 | HttpRequestInfo request; |
| 10930 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10931 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10932 | request.traffic_annotation = |
| 10933 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10934 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10935 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10936 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10937 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10938 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10939 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10940 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10941 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10942 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10943 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10944 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 10945 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10946 | |
| 10947 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10948 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10949 | base::size(write_buffer)), |
| 10950 | MockWrite("GET / HTTP/1.1\r\n" |
| 10951 | "Host: www.example.org\r\n" |
| 10952 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10953 | |
| 10954 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10955 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 10956 | base::size(read_buffer)), |
| 10957 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10958 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10959 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10960 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10961 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10962 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10963 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10964 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10965 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10966 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10967 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10968 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10969 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10970 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10971 | |
| 10972 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10973 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10974 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10975 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10976 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10977 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10978 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10979 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10980 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10981 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10982 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10983 | |
| 10984 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10985 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10986 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10987 | EXPECT_EQ("Payload", response_text); |
| 10988 | } |
| 10989 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10990 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10991 | HttpRequestInfo request; |
| 10992 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10993 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10994 | request.traffic_annotation = |
| 10995 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10996 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10997 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10998 | "socks4://myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10999 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11000 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11001 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11002 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11003 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11004 | |
| 11005 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 11006 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 11007 | |
| 11008 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11009 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 11010 | MockWrite("GET / HTTP/1.1\r\n" |
| 11011 | "Host: www.example.org\r\n" |
| 11012 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11013 | |
| 11014 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11015 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 11016 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11017 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11018 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11019 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11020 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11021 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11022 | |
| 11023 | TestCompletionCallback callback; |
| 11024 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11025 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11026 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11027 | |
| 11028 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11029 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11030 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11031 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11032 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11033 | |
| 11034 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11035 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11036 | TestLoadTimingNotReused(load_timing_info, |
| 11037 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 11038 | |
| 11039 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11040 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11041 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11042 | EXPECT_EQ("Payload", response_text); |
| 11043 | } |
| 11044 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11045 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11046 | HttpRequestInfo request; |
| 11047 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11048 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11049 | request.traffic_annotation = |
| 11050 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11051 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11052 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11053 | ProxyResolutionService::CreateFixedFromPacResult( |
| 11054 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11055 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11056 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11057 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11058 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11059 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11060 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11061 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 11062 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11063 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11064 | 0x05, // Version |
| 11065 | 0x01, // Command (CONNECT) |
| 11066 | 0x00, // Reserved. |
| 11067 | 0x03, // Address type (DOMAINNAME). |
| 11068 | 0x0F, // Length of domain (15) |
| 11069 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 11070 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11071 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11072 | const char kSOCKS5OkResponse[] = |
| 11073 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 11074 | |
| 11075 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11076 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
| 11077 | MockWrite(ASYNC, kSOCKS5OkRequest, base::size(kSOCKS5OkRequest)), |
| 11078 | MockWrite("GET / HTTP/1.1\r\n" |
| 11079 | "Host: www.example.org\r\n" |
| 11080 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11081 | |
| 11082 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11083 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 11084 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 11085 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11086 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11087 | MockRead("Payload"), |
| 11088 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11089 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11090 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11091 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11092 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11093 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11094 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11095 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11096 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11097 | |
| 11098 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11099 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11100 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11101 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11102 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11103 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11104 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11105 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11106 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11107 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11108 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 11109 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11110 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11111 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11112 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11113 | EXPECT_EQ("Payload", response_text); |
| 11114 | } |
| 11115 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11116 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11117 | HttpRequestInfo request; |
| 11118 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11119 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11120 | request.traffic_annotation = |
| 11121 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11122 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11123 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11124 | ProxyResolutionService::CreateFixedFromPacResult( |
| 11125 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 11126 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11127 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11128 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11129 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11130 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11131 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11132 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 11133 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11134 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11135 | 0x05, // Version |
| 11136 | 0x01, // Command (CONNECT) |
| 11137 | 0x00, // Reserved. |
| 11138 | 0x03, // Address type (DOMAINNAME). |
| 11139 | 0x0F, // Length of domain (15) |
| 11140 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 11141 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 11142 | }; |
| 11143 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11144 | const char kSOCKS5OkResponse[] = |
| 11145 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 11146 | |
| 11147 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11148 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11149 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11150 | base::size(kSOCKS5OkRequest)), |
| 11151 | MockWrite("GET / HTTP/1.1\r\n" |
| 11152 | "Host: www.example.org\r\n" |
| 11153 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11154 | |
| 11155 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11156 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 11157 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 11158 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11159 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11160 | MockRead("Payload"), |
| 11161 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11162 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11163 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11164 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11165 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11166 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11167 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11168 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11169 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11170 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11171 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11172 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11173 | |
| 11174 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11175 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11176 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11177 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11178 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11179 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11180 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11181 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11182 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11183 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11184 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 11185 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11186 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11187 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11188 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11189 | EXPECT_EQ("Payload", response_text); |
| 11190 | } |
| 11191 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11192 | namespace { |
| 11193 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11194 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11195 | |
| 11196 | struct GroupNameTest { |
| 11197 | std::string proxy_server; |
| 11198 | std::string url; |
| 11199 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11200 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11201 | }; |
| 11202 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11203 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11204 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11205 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11206 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11207 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11208 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11209 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11210 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11211 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 11212 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11213 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11214 | |
| 11215 | return session; |
| 11216 | } |
| 11217 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11218 | int GroupNameTransactionHelper(const std::string& url, |
| 11219 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11220 | HttpRequestInfo request; |
| 11221 | request.method = "GET"; |
| 11222 | request.url = GURL(url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11223 | request.traffic_annotation = |
| 11224 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11225 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11226 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11227 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11228 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11229 | |
| 11230 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11231 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11232 | } |
| 11233 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11234 | } // namespace |
| 11235 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11236 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11237 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11238 | { |
| 11239 | "", // unused |
| 11240 | "http://www.example.org/direct", |
| 11241 | "www.example.org:80", |
| 11242 | false, |
| 11243 | }, |
| 11244 | { |
| 11245 | "", // unused |
| 11246 | "http://[2001:1418:13:1::25]/direct", |
| 11247 | "[2001:1418:13:1::25]:80", |
| 11248 | false, |
| 11249 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11250 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11251 | // SSL Tests |
| 11252 | { |
| 11253 | "", // unused |
| 11254 | "https://www.example.org/direct_ssl", |
| 11255 | "ssl/www.example.org:443", |
| 11256 | true, |
| 11257 | }, |
| 11258 | { |
| 11259 | "", // unused |
| 11260 | "https://[2001:1418:13:1::25]/direct", |
| 11261 | "ssl/[2001:1418:13:1::25]:443", |
| 11262 | true, |
| 11263 | }, |
| 11264 | { |
| 11265 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 11266 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11267 | "ssl/host.with.alternate:443", |
| 11268 | true, |
| 11269 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11270 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11271 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11272 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11273 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11274 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11275 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11276 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 11277 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11278 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11279 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11280 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11281 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11282 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11283 | mock_pool_manager->SetSocketPool(ProxyServer::Direct(), |
| 11284 | base::WrapUnique(transport_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11285 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11286 | |
| 11287 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11288 | GroupNameTransactionHelper(tests[i].url, session.get())); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 11289 | EXPECT_EQ(tests[i].expected_group_name, |
| 11290 | transport_conn_pool->last_group_name_received()); |
| 11291 | EXPECT_TRUE(transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11292 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11293 | } |
| 11294 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11295 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11296 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11297 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11298 | "http_proxy", |
| 11299 | "http://www.example.org/http_proxy_normal", |
| 11300 | "www.example.org:80", |
| 11301 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11302 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11303 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11304 | // SSL Tests |
| 11305 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11306 | "http_proxy", |
| 11307 | "https://www.example.org/http_connect_ssl", |
| 11308 | "ssl/www.example.org:443", |
| 11309 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11310 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11311 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11312 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11313 | "http_proxy", |
| 11314 | "https://host.with.alternate/direct", |
| 11315 | "ssl/host.with.alternate:443", |
| 11316 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11317 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 11318 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11319 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11320 | "http_proxy", |
| 11321 | "ftp://ftp.google.com/http_proxy_normal", |
| 11322 | "ftp/ftp.google.com:21", |
| 11323 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11324 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11325 | }; |
| 11326 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11327 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11328 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11329 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11330 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11331 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 11332 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11333 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11334 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11335 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11336 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11337 | HostPortPair("http_proxy", 80)); |
Matt Menke | 0754b5d0 | 2019-02-10 21:46:43 | [diff] [blame] | 11338 | CaptureGroupNameTransportSocketPool* http_proxy_pool = |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 11339 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11340 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11341 | mock_pool_manager->SetSocketPool(proxy_server, |
| 11342 | base::WrapUnique(http_proxy_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11343 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11344 | |
| 11345 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11346 | GroupNameTransactionHelper(tests[i].url, session.get())); |
Matt Menke | aade581 | 2019-03-02 13:38:00 | [diff] [blame] | 11347 | EXPECT_EQ(tests[i].expected_group_name, |
| 11348 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11349 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11350 | } |
| 11351 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11352 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11353 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11354 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11355 | "socks4://socks_proxy:1080", |
| 11356 | "http://www.example.org/socks4_direct", |
| 11357 | "www.example.org:80", |
| 11358 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11359 | }, |
| 11360 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11361 | "socks5://socks_proxy:1080", |
| 11362 | "http://www.example.org/socks5_direct", |
| 11363 | "www.example.org:80", |
| 11364 | false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11365 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11366 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11367 | // SSL Tests |
| 11368 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11369 | "socks4://socks_proxy:1080", |
| 11370 | "https://www.example.org/socks4_ssl", |
| 11371 | "ssl/www.example.org:443", |
| 11372 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11373 | }, |
| 11374 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11375 | "socks5://socks_proxy:1080", |
| 11376 | "https://www.example.org/socks5_ssl", |
| 11377 | "ssl/www.example.org:443", |
| 11378 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11379 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11380 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11381 | { |
Matt Menke | 4802de6 | 2019-03-08 22:47:50 | [diff] [blame] | 11382 | "socks4://socks_proxy:1080", |
| 11383 | "https://host.with.alternate/direct", |
| 11384 | "ssl/host.with.alternate:443", |
| 11385 | true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11386 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11387 | }; |
| 11388 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11389 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11390 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11391 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11392 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11393 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 11394 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 11395 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11396 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11397 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11398 | ProxyServer proxy_server( |
| 11399 | ProxyServer::FromURI(tests[i].proxy_server, ProxyServer::SCHEME_HTTP)); |
| 11400 | ASSERT_TRUE(proxy_server.is_valid()); |
Matt Menke | 4b412da | 2019-01-25 19:31:12 | [diff] [blame] | 11401 | CaptureGroupNameTransportSocketPool* socks_conn_pool = |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 11402 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11403 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 11404 | mock_pool_manager->SetSocketPool(proxy_server, |
| 11405 | base::WrapUnique(socks_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11406 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11407 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11408 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11409 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11410 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11411 | GroupNameTransactionHelper(tests[i].url, session.get())); |
Matt Menke | 628d624f | 2019-02-09 00:40:24 | [diff] [blame] | 11412 | EXPECT_EQ(tests[i].expected_group_name, |
| 11413 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11414 | } |
| 11415 | } |
| 11416 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11417 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11418 | HttpRequestInfo request; |
| 11419 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11420 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11421 | request.traffic_annotation = |
| 11422 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11423 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11424 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11425 | "myproxy:70;foobar:80", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11426 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 11427 | // This simulates failure resolving all hostnames; that means we will fail |
| 11428 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11429 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11430 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11431 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11432 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11433 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11434 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11435 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11436 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11437 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11438 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11439 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11440 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11441 | } |
| 11442 | |
Miriam Gershenson | 2a01b16 | 2018-03-22 22:54:47 | [diff] [blame] | 11443 | // LOAD_BYPASS_CACHE should trigger the host cache bypass. |
| 11444 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11445 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 11446 | HttpRequestInfo request_info; |
| 11447 | request_info.method = "GET"; |
Miriam Gershenson | 2a01b16 | 2018-03-22 22:54:47 | [diff] [blame] | 11448 | request_info.load_flags = LOAD_BYPASS_CACHE; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 11449 | request_info.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11450 | request_info.traffic_annotation = |
| 11451 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11452 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 11453 | // Select a host resolver that does caching. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11454 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11455 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11456 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11457 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11458 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11459 | // Warm up the host cache so it has an entry for "www.example.org". |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 11460 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 11461 | HostPortPair("www.example.org", 80), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11462 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11463 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11464 | // Inject a failure the next time that "www.example.org" is resolved. This way |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11465 | // we can tell if the next lookup hit the cache, or the "network". |
| 11466 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11467 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11468 | |
| 11469 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 11470 | // first read -- this won't be reached as the host resolution will fail first. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11471 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11472 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11473 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11474 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11475 | // Run the request. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 11476 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11477 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11478 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11479 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11480 | |
| 11481 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11482 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11483 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11484 | } |
| 11485 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11486 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11487 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11488 | HttpRequestInfo request; |
| 11489 | request.method = "GET"; |
| 11490 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11491 | request.traffic_annotation = |
| 11492 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11493 | |
| 11494 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11495 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11496 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11497 | StaticSocketDataProvider data(base::span<MockRead>(), write_failure); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11498 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11499 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11500 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11501 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11502 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11503 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11504 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11505 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11506 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11507 | |
| 11508 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11509 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11510 | |
| 11511 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11512 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11513 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11514 | } |
| 11515 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11516 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11517 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11518 | HttpRequestInfo request; |
| 11519 | request.method = "GET"; |
| 11520 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11521 | request.traffic_annotation = |
| 11522 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11523 | |
| 11524 | MockRead data_reads[] = { |
| 11525 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11526 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11527 | }; |
| 11528 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11529 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11530 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11531 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11532 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11533 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11534 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11535 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11536 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11537 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11538 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11539 | |
| 11540 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11541 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11542 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11543 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11544 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11545 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11546 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11547 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11548 | |
| 11549 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11550 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11551 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11552 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11553 | |
| 11554 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11555 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11556 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11557 | } |
| 11558 | |
| 11559 | // Make sure that a dropped connection while draining the body for auth |
| 11560 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11561 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11562 | HttpRequestInfo request; |
| 11563 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11564 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11565 | request.traffic_annotation = |
| 11566 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11567 | |
| 11568 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11569 | MockWrite( |
| 11570 | "GET / HTTP/1.1\r\n" |
| 11571 | "Host: www.example.org\r\n" |
| 11572 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11573 | }; |
| 11574 | |
| 11575 | MockRead data_reads1[] = { |
| 11576 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 11577 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 11578 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11579 | MockRead("Content-Length: 14\r\n\r\n"), |
| 11580 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11581 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11582 | }; |
| 11583 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11584 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11585 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11586 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11587 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11588 | // be issuing -- the final header line contains the credentials. |
| 11589 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11590 | MockWrite( |
| 11591 | "GET / HTTP/1.1\r\n" |
| 11592 | "Host: www.example.org\r\n" |
| 11593 | "Connection: keep-alive\r\n" |
| 11594 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11595 | }; |
| 11596 | |
| 11597 | // Lastly, the server responds with the actual content. |
| 11598 | MockRead data_reads2[] = { |
| 11599 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11600 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11601 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11602 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11603 | }; |
| 11604 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11605 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11606 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11607 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11608 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11609 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11610 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11611 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11612 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11613 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11614 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11615 | |
| 11616 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11617 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11618 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11619 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11620 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11621 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11622 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11623 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11624 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11625 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11626 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11627 | |
| 11628 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11629 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11630 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11631 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11632 | ASSERT_TRUE(response); |
| 11633 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11634 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11635 | } |
| 11636 | |
| 11637 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11638 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11639 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11640 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11641 | |
| 11642 | HttpRequestInfo request; |
| 11643 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11644 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11645 | request.traffic_annotation = |
| 11646 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11647 | |
| 11648 | MockRead proxy_reads[] = { |
| 11649 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11650 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11651 | }; |
| 11652 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11653 | StaticSocketDataProvider data(proxy_reads, base::span<MockWrite>()); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11654 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11655 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11656 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11657 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11658 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11659 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11660 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11661 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11662 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11663 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11664 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11665 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11666 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11667 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11668 | |
| 11669 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11670 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11671 | } |
| 11672 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11673 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11674 | HttpRequestInfo request; |
| 11675 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11676 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11677 | request.traffic_annotation = |
| 11678 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11679 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11680 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11681 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11682 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11683 | MockRead data_reads[] = { |
| 11684 | MockRead("HTTP/1.0 200 OK\r\nContent-Length:6719476739\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11685 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11686 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11687 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11688 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11689 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11690 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11691 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11692 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11693 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11694 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11695 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11696 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11697 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11698 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11699 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11700 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11701 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11702 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11703 | |
| 11704 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11705 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11706 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11707 | } |
| 11708 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11709 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11710 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11711 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11712 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 11713 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 11714 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11715 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11716 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11717 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11718 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11719 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11720 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11721 | |
| 11722 | HttpRequestInfo request; |
| 11723 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11724 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11725 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11726 | request.traffic_annotation = |
| 11727 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11728 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11729 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11730 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11731 | |
| 11732 | MockRead data_reads[] = { |
| 11733 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 11734 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11735 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11736 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11737 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11738 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11739 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11740 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11741 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11742 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11743 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11744 | |
| 11745 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11746 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11747 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11748 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11749 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11750 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 11751 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11752 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11753 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11754 | } |
| 11755 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11756 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11757 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11758 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11759 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 11760 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 11761 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 11762 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 11763 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11764 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11765 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11766 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11767 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11768 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11769 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11770 | |
| 11771 | HttpRequestInfo request; |
| 11772 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11773 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11774 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11775 | request.traffic_annotation = |
| 11776 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11777 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 11778 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11779 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11780 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11781 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11782 | StaticSocketDataProvider data; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11783 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11784 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11785 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11786 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11787 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11788 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11789 | |
| 11790 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11791 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11792 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11793 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11794 | } |
| 11795 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11796 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11797 | class FakeUploadElementReader : public UploadElementReader { |
| 11798 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 11799 | FakeUploadElementReader() = default; |
| 11800 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11801 | |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11802 | CompletionOnceCallback TakeCallback() { return std::move(callback_); } |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11803 | |
| 11804 | // UploadElementReader overrides: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11805 | int Init(CompletionOnceCallback callback) override { |
| 11806 | callback_ = std::move(callback); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11807 | return ERR_IO_PENDING; |
| 11808 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11809 | uint64_t GetContentLength() const override { return 0; } |
| 11810 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11811 | int Read(IOBuffer* buf, |
| 11812 | int buf_length, |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11813 | CompletionOnceCallback callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11814 | return ERR_FAILED; |
| 11815 | } |
| 11816 | |
| 11817 | private: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11818 | CompletionOnceCallback callback_; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11819 | }; |
| 11820 | |
| 11821 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11822 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 11823 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11824 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11825 | |
| 11826 | HttpRequestInfo request; |
| 11827 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11828 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11829 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11830 | request.traffic_annotation = |
| 11831 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11832 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11833 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11834 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11835 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11836 | |
| 11837 | StaticSocketDataProvider data; |
| 11838 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11839 | |
| 11840 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11841 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11842 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 11843 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11844 | |
| 11845 | // Transaction is pending on request body initialization. |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11846 | CompletionOnceCallback init_callback = fake_reader->TakeCallback(); |
| 11847 | ASSERT_FALSE(init_callback.is_null()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11848 | |
| 11849 | // Return Init()'s result after the transaction gets destroyed. |
| 11850 | trans.reset(); |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11851 | std::move(init_callback).Run(OK); // Should not crash. |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11852 | } |
| 11853 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11854 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11855 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11856 | HttpRequestInfo request; |
| 11857 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11858 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11859 | request.traffic_annotation = |
| 11860 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11861 | |
| 11862 | // First transaction will request a resource and receive a Basic challenge |
| 11863 | // with realm="first_realm". |
| 11864 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11865 | MockWrite( |
| 11866 | "GET / HTTP/1.1\r\n" |
| 11867 | "Host: www.example.org\r\n" |
| 11868 | "Connection: keep-alive\r\n" |
| 11869 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11870 | }; |
| 11871 | MockRead data_reads1[] = { |
| 11872 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11873 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11874 | "\r\n"), |
| 11875 | }; |
| 11876 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11877 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11878 | // for first_realm. The server will reject and provide a challenge with |
| 11879 | // second_realm. |
| 11880 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11881 | MockWrite( |
| 11882 | "GET / HTTP/1.1\r\n" |
| 11883 | "Host: www.example.org\r\n" |
| 11884 | "Connection: keep-alive\r\n" |
| 11885 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 11886 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11887 | }; |
| 11888 | MockRead data_reads2[] = { |
| 11889 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11890 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 11891 | "\r\n"), |
| 11892 | }; |
| 11893 | |
| 11894 | // This again fails, and goes back to first_realm. Make sure that the |
| 11895 | // entry is removed from cache. |
| 11896 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11897 | MockWrite( |
| 11898 | "GET / HTTP/1.1\r\n" |
| 11899 | "Host: www.example.org\r\n" |
| 11900 | "Connection: keep-alive\r\n" |
| 11901 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 11902 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11903 | }; |
| 11904 | MockRead data_reads3[] = { |
| 11905 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11906 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11907 | "\r\n"), |
| 11908 | }; |
| 11909 | |
| 11910 | // Try one last time (with the correct password) and get the resource. |
| 11911 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11912 | MockWrite( |
| 11913 | "GET / HTTP/1.1\r\n" |
| 11914 | "Host: www.example.org\r\n" |
| 11915 | "Connection: keep-alive\r\n" |
| 11916 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 11917 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11918 | }; |
| 11919 | MockRead data_reads4[] = { |
| 11920 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11921 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11922 | "Content-Length: 5\r\n" |
| 11923 | "\r\n" |
| 11924 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11925 | }; |
| 11926 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11927 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 11928 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 11929 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
| 11930 | StaticSocketDataProvider data4(data_reads4, data_writes4); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11931 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 11932 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 11933 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 11934 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11935 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11936 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11937 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11938 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11939 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11940 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11941 | // Issue the first request with Authorize headers. There should be a |
| 11942 | // password prompt for first_realm waiting to be filled in after the |
| 11943 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11944 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11945 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11946 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11947 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11948 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11949 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11950 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11951 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11952 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11953 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11954 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11955 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11956 | |
| 11957 | // Issue the second request with an incorrect password. There should be a |
| 11958 | // password prompt for second_realm waiting to be filled in after the |
| 11959 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11960 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11961 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 11962 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11963 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11964 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11965 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11966 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11967 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11968 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11969 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11970 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11971 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11972 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11973 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11974 | |
| 11975 | // Issue the third request with another incorrect password. There should be |
| 11976 | // a password prompt for first_realm waiting to be filled in. If the password |
| 11977 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 11978 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11979 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11980 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 11981 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11982 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11983 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11984 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11985 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11986 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11987 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11988 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11989 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11990 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11991 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11992 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11993 | |
| 11994 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11995 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11996 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 11997 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11998 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11999 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12000 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12001 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12002 | ASSERT_TRUE(response); |
| 12003 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 12004 | } |
| 12005 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12006 | // Regression test for https://crbug.com/754395. |
| 12007 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 12008 | MockRead data_reads[] = { |
| 12009 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12010 | MockRead(kAlternativeServiceHttpHeader), |
| 12011 | MockRead("\r\n"), |
| 12012 | MockRead("hello world"), |
| 12013 | MockRead(SYNCHRONOUS, OK), |
| 12014 | }; |
| 12015 | |
| 12016 | HttpRequestInfo request; |
| 12017 | request.method = "GET"; |
| 12018 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12019 | request.traffic_annotation = |
| 12020 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12021 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12022 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12023 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12024 | |
| 12025 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12026 | ssl.ssl_info.cert = |
| 12027 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12028 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 12029 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 12030 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12031 | |
| 12032 | TestCompletionCallback callback; |
| 12033 | |
| 12034 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12035 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12036 | |
| 12037 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 12038 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12039 | |
| 12040 | url::SchemeHostPort test_server(request.url); |
| 12041 | HttpServerProperties* http_server_properties = |
| 12042 | session->http_server_properties(); |
| 12043 | EXPECT_TRUE( |
| 12044 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 12045 | |
| 12046 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 12047 | |
| 12048 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 12049 | ASSERT_TRUE(response); |
| 12050 | ASSERT_TRUE(response->headers); |
| 12051 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12052 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 12053 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 12054 | |
| 12055 | std::string response_data; |
| 12056 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 12057 | EXPECT_EQ("hello world", response_data); |
| 12058 | |
| 12059 | EXPECT_TRUE( |
| 12060 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 12061 | } |
| 12062 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12063 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12064 | MockRead data_reads[] = { |
| 12065 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12066 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12067 | MockRead("\r\n"), |
| 12068 | MockRead("hello world"), |
| 12069 | MockRead(SYNCHRONOUS, OK), |
| 12070 | }; |
| 12071 | |
| 12072 | HttpRequestInfo request; |
| 12073 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12074 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12075 | request.traffic_annotation = |
| 12076 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12077 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12078 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12079 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12080 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12081 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12082 | ssl.ssl_info.cert = |
| 12083 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12084 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12085 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12086 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12087 | TestCompletionCallback callback; |
| 12088 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12089 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12090 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12091 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12092 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12093 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12094 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12095 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12096 | HttpServerProperties* http_server_properties = |
| 12097 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12098 | EXPECT_TRUE( |
| 12099 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12100 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12101 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12102 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12103 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12104 | ASSERT_TRUE(response); |
| 12105 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12106 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12107 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12108 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12109 | |
| 12110 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12111 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12112 | EXPECT_EQ("hello world", response_data); |
| 12113 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12114 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 12115 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 12116 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12117 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 12118 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12119 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12120 | } |
| 12121 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12122 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12123 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12124 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12125 | MockRead data_reads[] = { |
| 12126 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12127 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12128 | MockRead("\r\n"), |
| 12129 | MockRead("hello world"), |
| 12130 | MockRead(SYNCHRONOUS, OK), |
| 12131 | }; |
| 12132 | |
| 12133 | HttpRequestInfo request; |
| 12134 | request.method = "GET"; |
| 12135 | request.url = GURL("http://www.example.org/"); |
| 12136 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12137 | request.traffic_annotation = |
| 12138 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12139 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12140 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12141 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12142 | |
| 12143 | TestCompletionCallback callback; |
| 12144 | |
| 12145 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12146 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12147 | |
| 12148 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12149 | HttpServerProperties* http_server_properties = |
| 12150 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12151 | EXPECT_TRUE( |
| 12152 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12153 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12154 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12155 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12156 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12157 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12158 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12159 | ASSERT_TRUE(response); |
| 12160 | ASSERT_TRUE(response->headers); |
| 12161 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12162 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12163 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12164 | |
| 12165 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12166 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12167 | EXPECT_EQ("hello world", response_data); |
| 12168 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12169 | EXPECT_TRUE( |
| 12170 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12171 | } |
| 12172 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12173 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12174 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12175 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12176 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12177 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12178 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12179 | HttpRequestInfo request; |
| 12180 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12181 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12182 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12183 | request.traffic_annotation = |
| 12184 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12185 | |
| 12186 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12187 | StaticSocketDataProvider first_data; |
| 12188 | first_data.set_connect_data(mock_connect); |
| 12189 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12190 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12191 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12192 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12193 | |
| 12194 | MockRead data_reads[] = { |
| 12195 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12196 | MockRead(ASYNC, OK), |
| 12197 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12198 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12199 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12200 | |
| 12201 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12202 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12203 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12204 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12205 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 12206 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12207 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12208 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12209 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 12210 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12211 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12212 | TestCompletionCallback callback; |
| 12213 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12214 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12215 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12216 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12217 | } |
| 12218 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12219 | // Regression test for https://crbug.com/615497: |
| 12220 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12221 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12222 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12223 | HttpRequestInfo request; |
| 12224 | request.method = "GET"; |
| 12225 | request.url = GURL("http://www.example.org/"); |
| 12226 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12227 | request.traffic_annotation = |
| 12228 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12229 | |
| 12230 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12231 | StaticSocketDataProvider first_data; |
| 12232 | first_data.set_connect_data(mock_connect); |
| 12233 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 12234 | |
| 12235 | MockRead data_reads[] = { |
| 12236 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12237 | MockRead(ASYNC, OK), |
| 12238 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12239 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12240 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12241 | |
| 12242 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12243 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12244 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12245 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12246 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12247 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12248 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12249 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 12250 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12251 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12252 | TestCompletionCallback callback; |
| 12253 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12254 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12255 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12256 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12257 | } |
| 12258 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12259 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12260 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12261 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12262 | HttpServerProperties* http_server_properties = |
| 12263 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12264 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12265 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12266 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12267 | http_server_properties->SetQuicAlternativeService( |
| 12268 | test_server, alternative_service, expiration, |
| 12269 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12270 | EXPECT_EQ( |
| 12271 | 1u, |
| 12272 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12273 | |
| 12274 | // Send a clear header. |
| 12275 | MockRead data_reads[] = { |
| 12276 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12277 | MockRead("Alt-Svc: clear\r\n"), |
| 12278 | MockRead("\r\n"), |
| 12279 | MockRead("hello world"), |
| 12280 | MockRead(SYNCHRONOUS, OK), |
| 12281 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12282 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12283 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12284 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12285 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12286 | ssl.ssl_info.cert = |
| 12287 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12288 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12289 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12290 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12291 | HttpRequestInfo request; |
| 12292 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12293 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12294 | request.traffic_annotation = |
| 12295 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12296 | |
| 12297 | TestCompletionCallback callback; |
| 12298 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12299 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12300 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12301 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12302 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12303 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12304 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12305 | ASSERT_TRUE(response); |
| 12306 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12307 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12308 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12309 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12310 | |
| 12311 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12312 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12313 | EXPECT_EQ("hello world", response_data); |
| 12314 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12315 | EXPECT_TRUE( |
| 12316 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12317 | } |
| 12318 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12319 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12320 | MockRead data_reads[] = { |
| 12321 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12322 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 12323 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12324 | MockRead("hello world"), |
| 12325 | MockRead(SYNCHRONOUS, OK), |
| 12326 | }; |
| 12327 | |
| 12328 | HttpRequestInfo request; |
| 12329 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12330 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12331 | request.traffic_annotation = |
| 12332 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12333 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12334 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12335 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12336 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12337 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12338 | ssl.ssl_info.cert = |
| 12339 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12340 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12341 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12342 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12343 | TestCompletionCallback callback; |
| 12344 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12345 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12346 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12347 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12348 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12349 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12350 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12351 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12352 | HttpServerProperties* http_server_properties = |
| 12353 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12354 | EXPECT_TRUE( |
| 12355 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12356 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12357 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12358 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12359 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12360 | ASSERT_TRUE(response); |
| 12361 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12362 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12363 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12364 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12365 | |
| 12366 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12367 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12368 | EXPECT_EQ("hello world", response_data); |
| 12369 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12370 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 12371 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 12372 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 12373 | |
| 12374 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 12375 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12376 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12377 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 12378 | 1234); |
| 12379 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12380 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12381 | } |
| 12382 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12383 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12384 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12385 | HostPortPair alternative("alternative.example.org", 443); |
| 12386 | std::string origin_url = "https://origin.example.org:443"; |
| 12387 | std::string alternative_url = "https://alternative.example.org:443"; |
| 12388 | |
| 12389 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12390 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12391 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12392 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12393 | |
| 12394 | // HTTP/1.1 data for request. |
| 12395 | MockWrite http_writes[] = { |
| 12396 | MockWrite("GET / HTTP/1.1\r\n" |
| 12397 | "Host: alternative.example.org\r\n" |
| 12398 | "Connection: keep-alive\r\n\r\n"), |
| 12399 | }; |
| 12400 | |
| 12401 | MockRead http_reads[] = { |
| 12402 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12403 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12404 | "Content-Length: 40\r\n\r\n" |
| 12405 | "first HTTP/1.1 response from alternative"), |
| 12406 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12407 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12408 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12409 | |
| 12410 | StaticSocketDataProvider data_refused; |
| 12411 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12412 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12413 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12414 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12415 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12416 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12417 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12418 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12419 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12420 | http_server_properties->SetQuicAlternativeService( |
| 12421 | server, alternative_service, expiration, |
| 12422 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12423 | // Mark the QUIC alternative service as broken. |
| 12424 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 12425 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12426 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12427 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12428 | request.method = "GET"; |
| 12429 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12430 | request.traffic_annotation = |
| 12431 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12432 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12433 | TestCompletionCallback callback; |
| 12434 | NetErrorDetails details; |
| 12435 | EXPECT_FALSE(details.quic_broken); |
| 12436 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12437 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12438 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12439 | EXPECT_TRUE(details.quic_broken); |
| 12440 | } |
| 12441 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12442 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12443 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12444 | HostPortPair alternative1("alternative1.example.org", 443); |
| 12445 | HostPortPair alternative2("alternative2.example.org", 443); |
| 12446 | std::string origin_url = "https://origin.example.org:443"; |
| 12447 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 12448 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 12449 | |
| 12450 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 12451 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12452 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12453 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12454 | |
| 12455 | // HTTP/1.1 data for request. |
| 12456 | MockWrite http_writes[] = { |
| 12457 | MockWrite("GET / HTTP/1.1\r\n" |
| 12458 | "Host: alternative1.example.org\r\n" |
| 12459 | "Connection: keep-alive\r\n\r\n"), |
| 12460 | }; |
| 12461 | |
| 12462 | MockRead http_reads[] = { |
| 12463 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12464 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12465 | "Content-Length: 40\r\n\r\n" |
| 12466 | "first HTTP/1.1 response from alternative1"), |
| 12467 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12468 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12469 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12470 | |
| 12471 | StaticSocketDataProvider data_refused; |
| 12472 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12473 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12474 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12475 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12476 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12477 | session->http_server_properties(); |
| 12478 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12479 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12480 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 12481 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 12482 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12483 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12484 | alternative_service_info_vector.push_back( |
| 12485 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12486 | alternative_service1, expiration, |
| 12487 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12488 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12489 | alternative_service_info_vector.push_back( |
| 12490 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12491 | alternative_service2, expiration, |
| 12492 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12493 | |
| 12494 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12495 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12496 | |
| 12497 | // Mark one of the QUIC alternative service as broken. |
| 12498 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12499 | EXPECT_EQ(2u, |
| 12500 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12501 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12502 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12503 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12504 | request.method = "GET"; |
| 12505 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12506 | request.traffic_annotation = |
| 12507 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12508 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12509 | TestCompletionCallback callback; |
| 12510 | NetErrorDetails details; |
| 12511 | EXPECT_FALSE(details.quic_broken); |
| 12512 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12513 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12514 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12515 | EXPECT_FALSE(details.quic_broken); |
| 12516 | } |
| 12517 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12518 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12519 | HttpRequestInfo request; |
| 12520 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12521 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12522 | request.traffic_annotation = |
| 12523 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12524 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12525 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12526 | StaticSocketDataProvider first_data; |
| 12527 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12528 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12529 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12530 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12531 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12532 | |
| 12533 | MockRead data_reads[] = { |
| 12534 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12535 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12536 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12537 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12538 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12539 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12540 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12541 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12542 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12543 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12544 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12545 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12546 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 12547 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12548 | // Port is ignored by MockConnect anyway. |
| 12549 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12550 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12551 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12552 | http_server_properties->SetHttp2AlternativeService( |
| 12553 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12554 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12555 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12556 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12557 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12558 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12559 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12560 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12561 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12562 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12563 | ASSERT_TRUE(response); |
| 12564 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12565 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12566 | |
| 12567 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12568 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12569 | EXPECT_EQ("hello world", response_data); |
| 12570 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12571 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 12572 | http_server_properties->GetAlternativeServiceInfos(server); |
| 12573 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12574 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12575 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12576 | EXPECT_TRUE( |
| 12577 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12578 | } |
| 12579 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12580 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12581 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12582 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12583 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12584 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12585 | HttpRequestInfo restricted_port_request; |
| 12586 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12587 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12588 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12589 | restricted_port_request.traffic_annotation = |
| 12590 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12591 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12592 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12593 | StaticSocketDataProvider first_data; |
| 12594 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12595 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12596 | |
| 12597 | MockRead data_reads[] = { |
| 12598 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12599 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12600 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12601 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12602 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12603 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12604 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12605 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12606 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12607 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12608 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12609 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12610 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12611 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12612 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12613 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12614 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12615 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12616 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12617 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12618 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12619 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12620 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12621 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12622 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12623 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12624 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12625 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12626 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12627 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12628 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12629 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12630 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 12631 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 12632 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12633 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12634 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12635 | |
| 12636 | HttpRequestInfo restricted_port_request; |
| 12637 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12638 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12639 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12640 | restricted_port_request.traffic_annotation = |
| 12641 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12642 | |
| 12643 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12644 | StaticSocketDataProvider first_data; |
| 12645 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12646 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12647 | |
| 12648 | MockRead data_reads[] = { |
| 12649 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12650 | MockRead("hello world"), |
| 12651 | MockRead(ASYNC, OK), |
| 12652 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12653 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12654 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12655 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12656 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12657 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12658 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12659 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12660 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12661 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12662 | session->http_server_properties(); |
| 12663 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12664 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12665 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12666 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12667 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12668 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12669 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12670 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12671 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12672 | TestCompletionCallback callback; |
| 12673 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12674 | EXPECT_EQ(ERR_IO_PENDING, |
| 12675 | trans.Start(&restricted_port_request, callback.callback(), |
| 12676 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12677 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12678 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12679 | } |
| 12680 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12681 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12682 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12683 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12684 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12685 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12686 | HttpRequestInfo restricted_port_request; |
| 12687 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12688 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12689 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12690 | restricted_port_request.traffic_annotation = |
| 12691 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12692 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12693 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12694 | StaticSocketDataProvider first_data; |
| 12695 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12696 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12697 | |
| 12698 | MockRead data_reads[] = { |
| 12699 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12700 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12701 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12702 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12703 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12704 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12705 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12706 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12707 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12708 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12709 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12710 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12711 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12712 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12713 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12714 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12715 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12716 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12717 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12718 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12719 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12720 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12721 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12722 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12723 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12724 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12725 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12726 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12727 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12728 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12729 | } |
| 12730 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12731 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12732 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12733 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12734 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12735 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12736 | HttpRequestInfo unrestricted_port_request; |
| 12737 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12738 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12739 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12740 | unrestricted_port_request.traffic_annotation = |
| 12741 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12742 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12743 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12744 | StaticSocketDataProvider first_data; |
| 12745 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12746 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12747 | |
| 12748 | MockRead data_reads[] = { |
| 12749 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12750 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12751 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12752 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12753 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12754 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12755 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12756 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12757 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12758 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12759 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12760 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12761 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12762 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12763 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12764 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12765 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12766 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12767 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12768 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12769 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12770 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12771 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12772 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12773 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12774 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12775 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12776 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12777 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12778 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12779 | } |
| 12780 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12781 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12782 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12783 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12784 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12785 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12786 | HttpRequestInfo unrestricted_port_request; |
| 12787 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12788 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12789 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12790 | unrestricted_port_request.traffic_annotation = |
| 12791 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12792 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12793 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12794 | StaticSocketDataProvider first_data; |
| 12795 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12796 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12797 | |
| 12798 | MockRead data_reads[] = { |
| 12799 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12800 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12801 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12802 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12803 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12804 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12805 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12806 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12807 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12808 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12809 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12810 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12811 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12812 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 12813 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12814 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12815 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12816 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12817 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12818 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12819 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12820 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12821 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12822 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12823 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12824 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12825 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12826 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12827 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12828 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12829 | } |
| 12830 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12831 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
Xida Chen | 9bfe0b6 | 2018-04-24 19:52:21 | [diff] [blame] | 12832 | // to an unsafe port, and that we resume the second HttpStreamFactory::Job once |
| 12833 | // the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12834 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12835 | HttpRequestInfo request; |
| 12836 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12837 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12838 | request.traffic_annotation = |
| 12839 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12840 | |
| 12841 | // The alternate protocol request will error out before we attempt to connect, |
| 12842 | // so only the standard HTTP request will try to connect. |
| 12843 | MockRead data_reads[] = { |
| 12844 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12845 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12846 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12847 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12848 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12849 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12850 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12851 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12852 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12853 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12854 | session->http_server_properties(); |
| 12855 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12856 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12857 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12858 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12859 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12860 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12861 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12862 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12863 | TestCompletionCallback callback; |
| 12864 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12865 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12866 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12867 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12868 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12869 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12870 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12871 | ASSERT_TRUE(response); |
| 12872 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12873 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12874 | |
| 12875 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12876 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12877 | EXPECT_EQ("hello world", response_data); |
| 12878 | } |
| 12879 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12880 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12881 | HttpRequestInfo request; |
| 12882 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12883 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12884 | request.traffic_annotation = |
| 12885 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12886 | |
| 12887 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12888 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12889 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12890 | MockRead("\r\n"), |
| 12891 | MockRead("hello world"), |
| 12892 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12893 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12894 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12895 | StaticSocketDataProvider first_transaction(data_reads, |
| 12896 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12897 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12898 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12899 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12900 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12901 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12902 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12903 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12904 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12905 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12906 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12907 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 12908 | spdy::SpdySerializedFrame resp( |
| 12909 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12910 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12911 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12912 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12913 | }; |
| 12914 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12915 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12916 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12917 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12918 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12919 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12920 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12921 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12922 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12923 | &hanging_non_alternate_protocol_socket); |
| 12924 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12925 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12926 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12927 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12928 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12929 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12930 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12931 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12932 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12933 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12934 | |
| 12935 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12936 | ASSERT_TRUE(response); |
| 12937 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12938 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12939 | |
| 12940 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12941 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12942 | EXPECT_EQ("hello world", response_data); |
| 12943 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12944 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12945 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12946 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12947 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12948 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12949 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12950 | |
| 12951 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12952 | ASSERT_TRUE(response); |
| 12953 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12954 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12955 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12956 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12957 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12958 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12959 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12960 | } |
| 12961 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12962 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12963 | HttpRequestInfo request; |
| 12964 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12965 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12966 | request.traffic_annotation = |
| 12967 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12968 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12969 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12970 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12971 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12972 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12973 | MockRead("\r\n"), |
| 12974 | MockRead("hello world"), |
| 12975 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12976 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12977 | }; |
| 12978 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12979 | StaticSocketDataProvider http11_data(data_reads, base::span<MockWrite>()); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12980 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12981 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12982 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12983 | ssl_http11.ssl_info.cert = |
| 12984 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12985 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12986 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 12987 | |
| 12988 | // Second transaction starts an alternative and a non-alternative Job. |
| 12989 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12990 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12991 | StaticSocketDataProvider hanging_socket1; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12992 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12993 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 12994 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12995 | StaticSocketDataProvider hanging_socket2; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12996 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 12997 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12998 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12999 | // Third transaction starts an alternative and a non-alternative job. |
| 13000 | // The non-alternative job hangs, but the alternative one succeeds. |
| 13001 | // The second transaction, still pending, binds to this socket. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13002 | spdy::SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13003 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13004 | spdy::SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13005 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13006 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13007 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13008 | }; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 13009 | spdy::SpdySerializedFrame resp1( |
| 13010 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13011 | spdy::SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 13012 | spdy::SpdySerializedFrame resp2( |
| 13013 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13014 | spdy::SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13015 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13016 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 13017 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13018 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13019 | }; |
| 13020 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13021 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13022 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13023 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13024 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13025 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13026 | StaticSocketDataProvider hanging_socket3; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13027 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 13028 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13029 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13030 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13031 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13032 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13033 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13034 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13035 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13036 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13037 | |
| 13038 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13039 | ASSERT_TRUE(response); |
| 13040 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13041 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13042 | |
| 13043 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13044 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13045 | EXPECT_EQ("hello world", response_data); |
| 13046 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13047 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13048 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13049 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13050 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13051 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13052 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 13053 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13054 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13055 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13056 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13057 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 13058 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13059 | |
| 13060 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13061 | ASSERT_TRUE(response); |
| 13062 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13063 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13064 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13065 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13066 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13067 | EXPECT_EQ("hello!", response_data); |
| 13068 | |
| 13069 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13070 | ASSERT_TRUE(response); |
| 13071 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13072 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13073 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13074 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13075 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13076 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13077 | } |
| 13078 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13079 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
Bence Béky | bcae3709 | 2018-06-12 04:18:53 | [diff] [blame] | 13080 | session_deps_.host_resolver->set_synchronous_mode(true); |
| 13081 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13082 | HttpRequestInfo request; |
| 13083 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13084 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13085 | request.traffic_annotation = |
| 13086 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13087 | |
| 13088 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13089 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13090 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13091 | MockRead("\r\n"), |
| 13092 | MockRead("hello world"), |
| 13093 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13094 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13095 | }; |
| 13096 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13097 | StaticSocketDataProvider first_transaction(data_reads, |
| 13098 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13099 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13100 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13101 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 13102 | ssl.ssl_info.cert = |
| 13103 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 13104 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13105 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13106 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13107 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13108 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13109 | hanging_alternate_protocol_socket.set_connect_data( |
| 13110 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13111 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13112 | &hanging_alternate_protocol_socket); |
| 13113 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13114 | // 2nd request is just a copy of the first one, over HTTP/1.1 again. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13115 | StaticSocketDataProvider second_transaction(data_reads, |
| 13116 | base::span<MockWrite>()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13117 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13118 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13119 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13120 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13121 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13122 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13123 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13124 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13125 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13126 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13127 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13128 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13129 | |
| 13130 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13131 | ASSERT_TRUE(response); |
| 13132 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13133 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13134 | |
| 13135 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13136 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13137 | EXPECT_EQ("hello world", response_data); |
| 13138 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13139 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13140 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13141 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13142 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13143 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13144 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13145 | |
| 13146 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13147 | ASSERT_TRUE(response); |
| 13148 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13149 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13150 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13151 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13152 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13153 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13154 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13155 | } |
| 13156 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13157 | // Test that proxy is resolved using the origin url, |
| 13158 | // regardless of the alternative server. |
| 13159 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 13160 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 13161 | ProxyConfig proxy_config; |
| 13162 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 13163 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13164 | auto proxy_config_service = std::make_unique<ProxyConfigServiceFixed>( |
| 13165 | ProxyConfigWithAnnotation(proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13166 | |
| 13167 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13168 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13169 | &capturing_proxy_resolver); |
| 13170 | |
| 13171 | TestNetLog net_log; |
| 13172 | |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 13173 | session_deps_.proxy_resolution_service = |
| 13174 | std::make_unique<ProxyResolutionService>( |
| 13175 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 13176 | &net_log); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13177 | |
| 13178 | session_deps_.net_log = &net_log; |
| 13179 | |
| 13180 | // Configure alternative service with a hostname that is not bypassed by the |
| 13181 | // proxy. |
| 13182 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13183 | HttpServerProperties* http_server_properties = |
| 13184 | session->http_server_properties(); |
| 13185 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13186 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13187 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13188 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13189 | http_server_properties->SetHttp2AlternativeService( |
| 13190 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13191 | |
| 13192 | // Non-alternative job should hang. |
| 13193 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13194 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13195 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 13196 | session_deps_.socket_factory->AddSocketDataProvider( |
| 13197 | &hanging_alternate_protocol_socket); |
| 13198 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13199 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13200 | |
| 13201 | HttpRequestInfo request; |
| 13202 | request.method = "GET"; |
| 13203 | request.url = GURL("https://www.example.org/"); |
| 13204 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13205 | request.traffic_annotation = |
| 13206 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13207 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13208 | spdy::SpdySerializedFrame req( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13209 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 13210 | |
| 13211 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 13212 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13213 | spdy::SpdySerializedFrame resp( |
| 13214 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13215 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13216 | MockRead spdy_reads[] = { |
| 13217 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 13218 | }; |
| 13219 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13220 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13221 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 13222 | |
| 13223 | TestCompletionCallback callback; |
| 13224 | |
| 13225 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13226 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13227 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13228 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 13229 | |
| 13230 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 13231 | ASSERT_TRUE(response); |
| 13232 | ASSERT_TRUE(response->headers); |
| 13233 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13234 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13235 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13236 | |
| 13237 | std::string response_data; |
| 13238 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 13239 | EXPECT_EQ("hello!", response_data); |
| 13240 | |
| 13241 | // Origin host bypasses proxy, no resolution should have happened. |
| 13242 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 13243 | } |
| 13244 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13245 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13246 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13247 | proxy_config.set_auto_detect(true); |
| 13248 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 13249 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13250 | CapturingProxyResolver capturing_proxy_resolver; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13251 | session_deps_.proxy_resolution_service = |
| 13252 | std::make_unique<ProxyResolutionService>( |
| 13253 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 13254 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 13255 | std::make_unique<CapturingProxyResolverFactory>( |
| 13256 | &capturing_proxy_resolver), |
| 13257 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13258 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13259 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13260 | |
| 13261 | HttpRequestInfo request; |
| 13262 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13263 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13264 | request.traffic_annotation = |
| 13265 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13266 | |
| 13267 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13268 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13269 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13270 | MockRead("\r\n"), |
| 13271 | MockRead("hello world"), |
| 13272 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13273 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13274 | }; |
| 13275 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13276 | StaticSocketDataProvider first_transaction(data_reads, |
| 13277 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13278 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13279 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13280 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13281 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13282 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13283 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13284 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13285 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13286 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13287 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13288 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13289 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13290 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13291 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13292 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13293 | }; |
| 13294 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13295 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 13296 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 13297 | spdy::SpdySerializedFrame resp( |
| 13298 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13299 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13300 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13301 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 13302 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13303 | }; |
| 13304 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13305 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13306 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13307 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13308 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13309 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13310 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 13311 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13312 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13313 | &hanging_non_alternate_protocol_socket); |
| 13314 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13315 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13316 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13317 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13318 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13319 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13320 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13321 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13322 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13323 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 13324 | |
| 13325 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13326 | ASSERT_TRUE(response); |
| 13327 | ASSERT_TRUE(response->headers); |
| 13328 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 13329 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13330 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13331 | |
| 13332 | std::string response_data; |
| 13333 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 13334 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13335 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13336 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13337 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13338 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13339 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13340 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13341 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13342 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13343 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13344 | ASSERT_TRUE(response); |
| 13345 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13346 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13347 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13348 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13349 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13350 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13351 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13352 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 13353 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13354 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13355 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13356 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13357 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13358 | LoadTimingInfo load_timing_info; |
| 13359 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 13360 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13361 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13362 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13363 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13364 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 13365 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13366 | HttpRequestInfo request; |
| 13367 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13368 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13369 | request.traffic_annotation = |
| 13370 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13371 | |
| 13372 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13373 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13374 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13375 | MockRead("\r\n"), |
| 13376 | MockRead("hello world"), |
| 13377 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13378 | }; |
| 13379 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13380 | StaticSocketDataProvider first_transaction(data_reads, |
| 13381 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13382 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13383 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13384 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13385 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13386 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13387 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13388 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13389 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13390 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13391 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13392 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 13393 | spdy::SpdySerializedFrame resp( |
| 13394 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13395 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13396 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13397 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13398 | }; |
| 13399 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13400 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13401 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13402 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 13403 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13404 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13405 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13406 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13407 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13408 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13409 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13410 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13411 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13412 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13413 | |
| 13414 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13415 | ASSERT_TRUE(response); |
| 13416 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13417 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13418 | |
| 13419 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13420 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13421 | EXPECT_EQ("hello world", response_data); |
| 13422 | |
| 13423 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13424 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13425 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 13426 | PRIVACY_MODE_DISABLED, |
| 13427 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13428 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 13429 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 13430 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13431 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13432 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13433 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13434 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13435 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13436 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13437 | |
| 13438 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13439 | ASSERT_TRUE(response); |
| 13440 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13441 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13442 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13443 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13444 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13445 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13446 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13447 | } |
| 13448 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13449 | // GenerateAuthToken is a mighty big test. |
| 13450 | // It tests all permutation of GenerateAuthToken behavior: |
| 13451 | // - Synchronous and Asynchronous completion. |
| 13452 | // - OK or error on completion. |
| 13453 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 13454 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 13455 | // - Non-authenticating and authenticating backend. |
| 13456 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 13457 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13458 | // problems generating an auth token for an authenticating proxy, we don't |
| 13459 | // need to test all permutations of the backend server). |
| 13460 | // |
| 13461 | // The test proceeds by going over each of the configuration cases, and |
| 13462 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 13463 | // specifies both the configuration for the test as well as the expectations |
| 13464 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13465 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13466 | static const char kServer[] = "http://www.example.com"; |
| 13467 | static const char kSecureServer[] = "https://www.example.com"; |
| 13468 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13469 | |
| 13470 | enum AuthTiming { |
| 13471 | AUTH_NONE, |
| 13472 | AUTH_SYNC, |
| 13473 | AUTH_ASYNC, |
| 13474 | }; |
| 13475 | |
| 13476 | const MockWrite kGet( |
| 13477 | "GET / HTTP/1.1\r\n" |
| 13478 | "Host: www.example.com\r\n" |
| 13479 | "Connection: keep-alive\r\n\r\n"); |
| 13480 | const MockWrite kGetProxy( |
| 13481 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13482 | "Host: www.example.com\r\n" |
| 13483 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13484 | const MockWrite kGetAuth( |
| 13485 | "GET / HTTP/1.1\r\n" |
| 13486 | "Host: www.example.com\r\n" |
| 13487 | "Connection: keep-alive\r\n" |
| 13488 | "Authorization: auth_token\r\n\r\n"); |
| 13489 | const MockWrite kGetProxyAuth( |
| 13490 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13491 | "Host: www.example.com\r\n" |
| 13492 | "Proxy-Connection: keep-alive\r\n" |
| 13493 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13494 | const MockWrite kGetAuthThroughProxy( |
| 13495 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13496 | "Host: www.example.com\r\n" |
| 13497 | "Proxy-Connection: keep-alive\r\n" |
| 13498 | "Authorization: auth_token\r\n\r\n"); |
| 13499 | const MockWrite kGetAuthWithProxyAuth( |
| 13500 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13501 | "Host: www.example.com\r\n" |
| 13502 | "Proxy-Connection: keep-alive\r\n" |
| 13503 | "Proxy-Authorization: auth_token\r\n" |
| 13504 | "Authorization: auth_token\r\n\r\n"); |
| 13505 | const MockWrite kConnect( |
| 13506 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13507 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13508 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13509 | const MockWrite kConnectProxyAuth( |
| 13510 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13511 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13512 | "Proxy-Connection: keep-alive\r\n" |
| 13513 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13514 | |
| 13515 | const MockRead kSuccess( |
| 13516 | "HTTP/1.1 200 OK\r\n" |
| 13517 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13518 | "Content-Length: 3\r\n\r\n" |
| 13519 | "Yes"); |
| 13520 | const MockRead kFailure( |
| 13521 | "Should not be called."); |
| 13522 | const MockRead kServerChallenge( |
| 13523 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13524 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13525 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13526 | "Content-Length: 14\r\n\r\n" |
| 13527 | "Unauthorized\r\n"); |
| 13528 | const MockRead kProxyChallenge( |
| 13529 | "HTTP/1.1 407 Unauthorized\r\n" |
| 13530 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 13531 | "Proxy-Connection: close\r\n" |
| 13532 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13533 | "Content-Length: 14\r\n\r\n" |
| 13534 | "Unauthorized\r\n"); |
| 13535 | const MockRead kProxyConnected( |
| 13536 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 13537 | |
| 13538 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 13539 | // no constructors, but the C++ compiler on Windows warns about |
| 13540 | // unspecified data in compound literals. So, moved to using constructors, |
| 13541 | // and TestRound's created with the default constructor should not be used. |
| 13542 | struct TestRound { |
| 13543 | TestRound() |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 13544 | : expected_rv(ERR_UNEXPECTED), |
| 13545 | extra_write(nullptr), |
| 13546 | extra_read(nullptr) {} |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 13547 | TestRound(const MockWrite& write_arg, |
| 13548 | const MockRead& read_arg, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13549 | int expected_rv_arg) |
| 13550 | : write(write_arg), |
| 13551 | read(read_arg), |
| 13552 | expected_rv(expected_rv_arg), |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 13553 | extra_write(nullptr), |
| 13554 | extra_read(nullptr) {} |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13555 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 13556 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 13557 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13558 | : write(write_arg), |
| 13559 | read(read_arg), |
| 13560 | expected_rv(expected_rv_arg), |
| 13561 | extra_write(extra_write_arg), |
| 13562 | extra_read(extra_read_arg) { |
| 13563 | } |
| 13564 | MockWrite write; |
| 13565 | MockRead read; |
| 13566 | int expected_rv; |
| 13567 | const MockWrite* extra_write; |
| 13568 | const MockRead* extra_read; |
| 13569 | }; |
| 13570 | |
| 13571 | static const int kNoSSL = 500; |
| 13572 | |
| 13573 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13574 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13575 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13576 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13577 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13578 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13579 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13580 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13581 | int num_auth_rounds; |
| 13582 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13583 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13584 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13585 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13586 | {__LINE__, |
| 13587 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13588 | AUTH_NONE, |
| 13589 | OK, |
| 13590 | kServer, |
| 13591 | AUTH_NONE, |
| 13592 | OK, |
| 13593 | 1, |
| 13594 | kNoSSL, |
| 13595 | {TestRound(kGet, kSuccess, OK)}}, |
| 13596 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13597 | {__LINE__, |
| 13598 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13599 | AUTH_NONE, |
| 13600 | OK, |
| 13601 | kServer, |
| 13602 | AUTH_SYNC, |
| 13603 | OK, |
| 13604 | 2, |
| 13605 | kNoSSL, |
| 13606 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13607 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13608 | {__LINE__, |
| 13609 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13610 | AUTH_NONE, |
| 13611 | OK, |
| 13612 | kServer, |
| 13613 | AUTH_SYNC, |
| 13614 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13615 | 3, |
| 13616 | kNoSSL, |
| 13617 | {TestRound(kGet, kServerChallenge, OK), |
| 13618 | TestRound(kGet, kServerChallenge, OK), |
| 13619 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13620 | {__LINE__, |
| 13621 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13622 | AUTH_NONE, |
| 13623 | OK, |
| 13624 | kServer, |
| 13625 | AUTH_SYNC, |
| 13626 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13627 | 2, |
| 13628 | kNoSSL, |
| 13629 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13630 | {__LINE__, |
| 13631 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13632 | AUTH_NONE, |
| 13633 | OK, |
| 13634 | kServer, |
| 13635 | AUTH_SYNC, |
| 13636 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 13637 | 2, |
| 13638 | kNoSSL, |
| 13639 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13640 | {__LINE__, |
| 13641 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13642 | AUTH_SYNC, |
| 13643 | ERR_FAILED, |
| 13644 | kServer, |
| 13645 | AUTH_NONE, |
| 13646 | OK, |
| 13647 | 2, |
| 13648 | kNoSSL, |
| 13649 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13650 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13651 | {__LINE__, |
| 13652 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13653 | AUTH_ASYNC, |
| 13654 | ERR_FAILED, |
| 13655 | kServer, |
| 13656 | AUTH_NONE, |
| 13657 | OK, |
| 13658 | 2, |
| 13659 | kNoSSL, |
| 13660 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13661 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13662 | {__LINE__, |
| 13663 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13664 | AUTH_NONE, |
| 13665 | OK, |
| 13666 | kServer, |
| 13667 | AUTH_SYNC, |
| 13668 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13669 | 2, |
| 13670 | kNoSSL, |
| 13671 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13672 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13673 | {__LINE__, |
| 13674 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13675 | AUTH_NONE, |
| 13676 | OK, |
| 13677 | kServer, |
| 13678 | AUTH_ASYNC, |
| 13679 | ERR_FAILED, |
| 13680 | 2, |
| 13681 | kNoSSL, |
| 13682 | {TestRound(kGet, kServerChallenge, OK), |
| 13683 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13684 | {__LINE__, |
| 13685 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13686 | AUTH_NONE, |
| 13687 | OK, |
| 13688 | kServer, |
| 13689 | AUTH_ASYNC, |
| 13690 | OK, |
| 13691 | 2, |
| 13692 | kNoSSL, |
| 13693 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13694 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13695 | {__LINE__, |
| 13696 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13697 | AUTH_NONE, |
| 13698 | OK, |
| 13699 | kServer, |
| 13700 | AUTH_ASYNC, |
| 13701 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13702 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13703 | kNoSSL, |
| 13704 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13705 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 13706 | TestRound(kGet, kServerChallenge, OK), |
| 13707 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13708 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13709 | {__LINE__, |
| 13710 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13711 | AUTH_NONE, |
| 13712 | OK, |
| 13713 | kServer, |
| 13714 | AUTH_NONE, |
| 13715 | OK, |
| 13716 | 1, |
| 13717 | kNoSSL, |
| 13718 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 13719 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13720 | {__LINE__, |
| 13721 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13722 | AUTH_NONE, |
| 13723 | OK, |
| 13724 | kServer, |
| 13725 | AUTH_SYNC, |
| 13726 | OK, |
| 13727 | 2, |
| 13728 | kNoSSL, |
| 13729 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13730 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13731 | {__LINE__, |
| 13732 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13733 | AUTH_NONE, |
| 13734 | OK, |
| 13735 | kServer, |
| 13736 | AUTH_SYNC, |
| 13737 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13738 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13739 | kNoSSL, |
| 13740 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13741 | TestRound(kGetProxy, kServerChallenge, OK), |
| 13742 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13743 | {__LINE__, |
| 13744 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13745 | AUTH_NONE, |
| 13746 | OK, |
| 13747 | kServer, |
| 13748 | AUTH_ASYNC, |
| 13749 | OK, |
| 13750 | 2, |
| 13751 | kNoSSL, |
| 13752 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13753 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13754 | {__LINE__, |
| 13755 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13756 | AUTH_NONE, |
| 13757 | OK, |
| 13758 | kServer, |
| 13759 | AUTH_ASYNC, |
| 13760 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13761 | 2, |
| 13762 | kNoSSL, |
| 13763 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13764 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13765 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13766 | {__LINE__, |
| 13767 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13768 | AUTH_SYNC, |
| 13769 | OK, |
| 13770 | kServer, |
| 13771 | AUTH_NONE, |
| 13772 | OK, |
| 13773 | 2, |
| 13774 | kNoSSL, |
| 13775 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13776 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13777 | {__LINE__, |
| 13778 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13779 | AUTH_SYNC, |
| 13780 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13781 | kServer, |
| 13782 | AUTH_NONE, |
| 13783 | OK, |
| 13784 | 2, |
| 13785 | kNoSSL, |
| 13786 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13787 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13788 | {__LINE__, |
| 13789 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13790 | AUTH_ASYNC, |
| 13791 | OK, |
| 13792 | kServer, |
| 13793 | AUTH_NONE, |
| 13794 | OK, |
| 13795 | 2, |
| 13796 | kNoSSL, |
| 13797 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13798 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13799 | {__LINE__, |
| 13800 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13801 | AUTH_ASYNC, |
| 13802 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13803 | kServer, |
| 13804 | AUTH_NONE, |
| 13805 | OK, |
| 13806 | 2, |
| 13807 | kNoSSL, |
| 13808 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13809 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13810 | {__LINE__, |
| 13811 | kProxy, |
| 13812 | AUTH_ASYNC, |
| 13813 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13814 | kServer, |
| 13815 | AUTH_NONE, |
| 13816 | OK, |
| 13817 | 3, |
| 13818 | kNoSSL, |
| 13819 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13820 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13821 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13822 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13823 | {__LINE__, |
| 13824 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13825 | AUTH_SYNC, |
| 13826 | OK, |
| 13827 | kServer, |
| 13828 | AUTH_SYNC, |
| 13829 | OK, |
| 13830 | 3, |
| 13831 | kNoSSL, |
| 13832 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13833 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13834 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13835 | {__LINE__, |
| 13836 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13837 | AUTH_SYNC, |
| 13838 | OK, |
| 13839 | kServer, |
| 13840 | AUTH_SYNC, |
| 13841 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13842 | 3, |
| 13843 | kNoSSL, |
| 13844 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13845 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13846 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13847 | {__LINE__, |
| 13848 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13849 | AUTH_ASYNC, |
| 13850 | OK, |
| 13851 | kServer, |
| 13852 | AUTH_SYNC, |
| 13853 | OK, |
| 13854 | 3, |
| 13855 | kNoSSL, |
| 13856 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13857 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13858 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13859 | {__LINE__, |
| 13860 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13861 | AUTH_ASYNC, |
| 13862 | OK, |
| 13863 | kServer, |
| 13864 | AUTH_SYNC, |
| 13865 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13866 | 3, |
| 13867 | kNoSSL, |
| 13868 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13869 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13870 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13871 | {__LINE__, |
| 13872 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13873 | AUTH_SYNC, |
| 13874 | OK, |
| 13875 | kServer, |
| 13876 | AUTH_ASYNC, |
| 13877 | OK, |
| 13878 | 3, |
| 13879 | kNoSSL, |
| 13880 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13881 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13882 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13883 | {__LINE__, |
| 13884 | kProxy, |
| 13885 | AUTH_SYNC, |
| 13886 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13887 | kServer, |
| 13888 | AUTH_ASYNC, |
| 13889 | OK, |
| 13890 | 4, |
| 13891 | kNoSSL, |
| 13892 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13893 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13894 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13895 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 13896 | {__LINE__, |
| 13897 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13898 | AUTH_SYNC, |
| 13899 | OK, |
| 13900 | kServer, |
| 13901 | AUTH_ASYNC, |
| 13902 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13903 | 3, |
| 13904 | kNoSSL, |
| 13905 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13906 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13907 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13908 | {__LINE__, |
| 13909 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13910 | AUTH_ASYNC, |
| 13911 | OK, |
| 13912 | kServer, |
| 13913 | AUTH_ASYNC, |
| 13914 | OK, |
| 13915 | 3, |
| 13916 | kNoSSL, |
| 13917 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13918 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13919 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13920 | {__LINE__, |
| 13921 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13922 | AUTH_ASYNC, |
| 13923 | OK, |
| 13924 | kServer, |
| 13925 | AUTH_ASYNC, |
| 13926 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13927 | 3, |
| 13928 | kNoSSL, |
| 13929 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13930 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13931 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13932 | {__LINE__, |
| 13933 | kProxy, |
| 13934 | AUTH_ASYNC, |
| 13935 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13936 | kServer, |
| 13937 | AUTH_ASYNC, |
| 13938 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13939 | 4, |
| 13940 | kNoSSL, |
| 13941 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13942 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13943 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13944 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13945 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13946 | {__LINE__, |
| 13947 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13948 | AUTH_NONE, |
| 13949 | OK, |
| 13950 | kSecureServer, |
| 13951 | AUTH_NONE, |
| 13952 | OK, |
| 13953 | 1, |
| 13954 | 0, |
| 13955 | {TestRound(kGet, kSuccess, OK)}}, |
| 13956 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13957 | {__LINE__, |
| 13958 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13959 | AUTH_NONE, |
| 13960 | OK, |
| 13961 | kSecureServer, |
| 13962 | AUTH_SYNC, |
| 13963 | OK, |
| 13964 | 2, |
| 13965 | 0, |
| 13966 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13967 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13968 | {__LINE__, |
| 13969 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13970 | AUTH_NONE, |
| 13971 | OK, |
| 13972 | kSecureServer, |
| 13973 | AUTH_SYNC, |
| 13974 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13975 | 2, |
| 13976 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13977 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13978 | {__LINE__, |
| 13979 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13980 | AUTH_NONE, |
| 13981 | OK, |
| 13982 | kSecureServer, |
| 13983 | AUTH_ASYNC, |
| 13984 | OK, |
| 13985 | 2, |
| 13986 | 0, |
| 13987 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13988 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13989 | {__LINE__, |
| 13990 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13991 | AUTH_NONE, |
| 13992 | OK, |
| 13993 | kSecureServer, |
| 13994 | AUTH_ASYNC, |
| 13995 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13996 | 2, |
| 13997 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13998 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13999 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14000 | {__LINE__, |
| 14001 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14002 | AUTH_NONE, |
| 14003 | OK, |
| 14004 | kSecureServer, |
| 14005 | AUTH_NONE, |
| 14006 | OK, |
| 14007 | 1, |
| 14008 | 0, |
| 14009 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 14010 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14011 | {__LINE__, |
| 14012 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14013 | AUTH_NONE, |
| 14014 | OK, |
| 14015 | kSecureServer, |
| 14016 | AUTH_SYNC, |
| 14017 | OK, |
| 14018 | 2, |
| 14019 | 0, |
| 14020 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14021 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14022 | {__LINE__, |
| 14023 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14024 | AUTH_NONE, |
| 14025 | OK, |
| 14026 | kSecureServer, |
| 14027 | AUTH_SYNC, |
| 14028 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14029 | 2, |
| 14030 | 0, |
| 14031 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14032 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14033 | {__LINE__, |
| 14034 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14035 | AUTH_NONE, |
| 14036 | OK, |
| 14037 | kSecureServer, |
| 14038 | AUTH_ASYNC, |
| 14039 | OK, |
| 14040 | 2, |
| 14041 | 0, |
| 14042 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14043 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14044 | {__LINE__, |
| 14045 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14046 | AUTH_NONE, |
| 14047 | OK, |
| 14048 | kSecureServer, |
| 14049 | AUTH_ASYNC, |
| 14050 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14051 | 2, |
| 14052 | 0, |
| 14053 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14054 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14055 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14056 | {__LINE__, |
| 14057 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14058 | AUTH_SYNC, |
| 14059 | OK, |
| 14060 | kSecureServer, |
| 14061 | AUTH_NONE, |
| 14062 | OK, |
| 14063 | 2, |
| 14064 | 1, |
| 14065 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14066 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14067 | {__LINE__, |
| 14068 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14069 | AUTH_SYNC, |
| 14070 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14071 | kSecureServer, |
| 14072 | AUTH_NONE, |
| 14073 | OK, |
| 14074 | 2, |
| 14075 | kNoSSL, |
| 14076 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14077 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14078 | {__LINE__, |
| 14079 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14080 | AUTH_SYNC, |
| 14081 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 14082 | kSecureServer, |
| 14083 | AUTH_NONE, |
| 14084 | OK, |
| 14085 | 2, |
| 14086 | kNoSSL, |
| 14087 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14088 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14089 | {__LINE__, |
| 14090 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14091 | AUTH_SYNC, |
| 14092 | ERR_UNEXPECTED, |
| 14093 | kSecureServer, |
| 14094 | AUTH_NONE, |
| 14095 | OK, |
| 14096 | 2, |
| 14097 | kNoSSL, |
| 14098 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14099 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14100 | {__LINE__, |
| 14101 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14102 | AUTH_ASYNC, |
| 14103 | OK, |
| 14104 | kSecureServer, |
| 14105 | AUTH_NONE, |
| 14106 | OK, |
| 14107 | 2, |
| 14108 | 1, |
| 14109 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14110 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14111 | {__LINE__, |
| 14112 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14113 | AUTH_ASYNC, |
| 14114 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14115 | kSecureServer, |
| 14116 | AUTH_NONE, |
| 14117 | OK, |
| 14118 | 2, |
| 14119 | kNoSSL, |
| 14120 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14121 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14122 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14123 | {__LINE__, |
| 14124 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14125 | AUTH_SYNC, |
| 14126 | OK, |
| 14127 | kSecureServer, |
| 14128 | AUTH_SYNC, |
| 14129 | OK, |
| 14130 | 3, |
| 14131 | 1, |
| 14132 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14133 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14134 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14135 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14136 | {__LINE__, |
| 14137 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14138 | AUTH_SYNC, |
| 14139 | OK, |
| 14140 | kSecureServer, |
| 14141 | AUTH_SYNC, |
| 14142 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14143 | 3, |
| 14144 | 1, |
| 14145 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14146 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14147 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14148 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14149 | {__LINE__, |
| 14150 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14151 | AUTH_ASYNC, |
| 14152 | OK, |
| 14153 | kSecureServer, |
| 14154 | AUTH_SYNC, |
| 14155 | OK, |
| 14156 | 3, |
| 14157 | 1, |
| 14158 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14159 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14160 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14161 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14162 | {__LINE__, |
| 14163 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14164 | AUTH_ASYNC, |
| 14165 | OK, |
| 14166 | kSecureServer, |
| 14167 | AUTH_SYNC, |
| 14168 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14169 | 3, |
| 14170 | 1, |
| 14171 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14172 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14173 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14174 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14175 | {__LINE__, |
| 14176 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14177 | AUTH_SYNC, |
| 14178 | OK, |
| 14179 | kSecureServer, |
| 14180 | AUTH_ASYNC, |
| 14181 | OK, |
| 14182 | 3, |
| 14183 | 1, |
| 14184 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14185 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14186 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14187 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14188 | {__LINE__, |
| 14189 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14190 | AUTH_SYNC, |
| 14191 | OK, |
| 14192 | kSecureServer, |
| 14193 | AUTH_ASYNC, |
| 14194 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14195 | 3, |
| 14196 | 1, |
| 14197 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14198 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14199 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14200 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14201 | {__LINE__, |
| 14202 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14203 | AUTH_ASYNC, |
| 14204 | OK, |
| 14205 | kSecureServer, |
| 14206 | AUTH_ASYNC, |
| 14207 | OK, |
| 14208 | 3, |
| 14209 | 1, |
| 14210 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14211 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14212 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14213 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14214 | {__LINE__, |
| 14215 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14216 | AUTH_ASYNC, |
| 14217 | OK, |
| 14218 | kSecureServer, |
| 14219 | AUTH_ASYNC, |
| 14220 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14221 | 3, |
| 14222 | 1, |
| 14223 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14224 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14225 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14226 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14227 | {__LINE__, |
| 14228 | kProxy, |
| 14229 | AUTH_ASYNC, |
| 14230 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14231 | kSecureServer, |
| 14232 | AUTH_ASYNC, |
| 14233 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14234 | 4, |
| 14235 | 2, |
| 14236 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14237 | TestRound(kConnect, kProxyChallenge, OK), |
| 14238 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14239 | &kServerChallenge), |
| 14240 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14241 | }; |
| 14242 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14243 | for (const auto& test_config : test_configs) { |
| 14244 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 14245 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14246 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14247 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14248 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14249 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14250 | |
| 14251 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14252 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14253 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14254 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14255 | std::string auth_challenge = "Mock realm=proxy"; |
| 14256 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14257 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14258 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14259 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14260 | empty_ssl_info, origin, |
| 14261 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14262 | auth_handler->SetGenerateExpectation( |
| 14263 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14264 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14265 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 14266 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14267 | } |
| 14268 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 14269 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14270 | std::string auth_challenge = "Mock realm=server"; |
| 14271 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14272 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14273 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14274 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14275 | empty_ssl_info, origin, |
| 14276 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14277 | auth_handler->SetGenerateExpectation( |
| 14278 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14279 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14280 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14281 | |
| 14282 | // The second handler always succeeds. It should only be used where there |
| 14283 | // are multiple auth sessions for server auth in the same network |
| 14284 | // transaction using the same auth scheme. |
| 14285 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14286 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14287 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 14288 | empty_ssl_info, origin, |
| 14289 | NetLogWithSource()); |
| 14290 | second_handler->SetGenerateExpectation(true, OK); |
| 14291 | auth_factory->AddMockHandler(second_handler.release(), |
| 14292 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14293 | } |
| 14294 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14295 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14296 | ProxyResolutionService::CreateFixed(test_config.proxy_url, |
| 14297 | TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14298 | } else { |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14299 | session_deps_.proxy_resolution_service = |
| 14300 | ProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14301 | } |
| 14302 | |
| 14303 | HttpRequestInfo request; |
| 14304 | request.method = "GET"; |
| 14305 | request.url = GURL(test_config.server_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14306 | request.traffic_annotation = |
| 14307 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14308 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14309 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14310 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14311 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 14312 | |
| 14313 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 14314 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14315 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14316 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14317 | const TestRound& read_write_round = test_config.rounds[round]; |
| 14318 | |
| 14319 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14320 | mock_reads.back().push_back(read_write_round.read); |
| 14321 | mock_writes.back().push_back(read_write_round.write); |
| 14322 | |
| 14323 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 14324 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 14325 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14326 | mock_reads.push_back(std::vector<MockRead>()); |
| 14327 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14328 | } |
| 14329 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14330 | if (read_write_round.extra_read) { |
| 14331 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14332 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14333 | if (read_write_round.extra_write) { |
| 14334 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 14335 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14336 | |
| 14337 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14338 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14339 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14340 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14341 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14342 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14343 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14344 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14345 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14346 | mock_reads[i], mock_writes[i])); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14347 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 14348 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14349 | } |
| 14350 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 14351 | // Transaction must be created after DataProviders, so it's destroyed before |
| 14352 | // they are as well. |
| 14353 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 14354 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14355 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14356 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14357 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14358 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14359 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14360 | int rv; |
| 14361 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14362 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14363 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14364 | rv = trans.RestartWithAuth( |
| 14365 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14366 | } |
| 14367 | if (rv == ERR_IO_PENDING) |
| 14368 | rv = callback.WaitForResult(); |
| 14369 | |
| 14370 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14371 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14372 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 14373 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14374 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 14375 | continue; |
| 14376 | } |
| 14377 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14378 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14379 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14380 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14381 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14382 | } |
| 14383 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 14384 | } |
| 14385 | } |
| 14386 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14387 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14388 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14389 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14390 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14391 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14392 | session_deps_.proxy_resolution_service = |
| 14393 | ProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14394 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14395 | |
| 14396 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14397 | auth_handler->set_connection_based(true); |
| 14398 | std::string auth_challenge = "Mock realm=server"; |
| 14399 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14400 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14401 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14402 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14403 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14404 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14405 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14406 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14407 | int rv = OK; |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 14408 | const HttpResponseInfo* response = nullptr; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14409 | HttpRequestInfo request; |
| 14410 | request.method = "GET"; |
| 14411 | request.url = origin; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14412 | request.traffic_annotation = |
| 14413 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14414 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14415 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14416 | |
| 14417 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 14418 | // to validate that the TCP socket is not released to the pool between |
| 14419 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14420 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14421 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
Tarun Bansal | a763509 | 2019-02-20 10:00:59 | [diff] [blame] | 14422 | 50, // Max sockets for pool |
| 14423 | 1, // Max sockets per group |
| 14424 | base::TimeDelta::FromSeconds(10), // unused_idle_socket_timeout |
Matt Menke | cb77b540 | 2019-01-28 17:11:23 | [diff] [blame] | 14425 | session_deps_.socket_factory.get(), session_deps_.host_resolver.get(), |
Matt Menke | d732ea4 | 2019-03-08 12:05:00 | [diff] [blame] | 14426 | nullptr /* proxy_delegate */, nullptr /* http_user_agent_settings */, |
| 14427 | session_deps_.cert_verifier.get(), session_deps_.channel_id_service.get(), |
Matt Menke | cb77b540 | 2019-01-28 17:11:23 | [diff] [blame] | 14428 | session_deps_.transport_security_state.get(), |
| 14429 | session_deps_.cert_transparency_verifier.get(), |
| 14430 | session_deps_.ct_policy_enforcer.get(), |
Matt Menke | c94d97b | 2019-02-01 19:28:28 | [diff] [blame] | 14431 | nullptr /* ssl_client_session_cache */, |
Daniel McArdle | da3fa94 | 2019-02-15 16:41:21 | [diff] [blame] | 14432 | nullptr /* ssl_client_session_cache_privacy_mode */, |
Matt Menke | fa9574f | 2019-01-28 18:55:27 | [diff] [blame] | 14433 | session_deps_.ssl_config_service.get(), |
Matt Menke | cb77b540 | 2019-01-28 17:11:23 | [diff] [blame] | 14434 | nullptr /* socket_performance_watcher_factory */, |
| 14435 | nullptr /* network_quality_estimator */, session_deps_.net_log); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14436 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | d23ab95 | 2019-03-06 00:24:40 | [diff] [blame] | 14437 | mock_pool_manager->SetSocketPool(ProxyServer::Direct(), |
| 14438 | base::WrapUnique(transport_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14439 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14440 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14441 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14442 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14443 | |
| 14444 | const MockWrite kGet( |
| 14445 | "GET / HTTP/1.1\r\n" |
| 14446 | "Host: www.example.com\r\n" |
| 14447 | "Connection: keep-alive\r\n\r\n"); |
| 14448 | const MockWrite kGetAuth( |
| 14449 | "GET / HTTP/1.1\r\n" |
| 14450 | "Host: www.example.com\r\n" |
| 14451 | "Connection: keep-alive\r\n" |
| 14452 | "Authorization: auth_token\r\n\r\n"); |
| 14453 | |
| 14454 | const MockRead kServerChallenge( |
| 14455 | "HTTP/1.1 401 Unauthorized\r\n" |
| 14456 | "WWW-Authenticate: Mock realm=server\r\n" |
| 14457 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14458 | "Content-Length: 14\r\n\r\n" |
| 14459 | "Unauthorized\r\n"); |
| 14460 | const MockRead kSuccess( |
| 14461 | "HTTP/1.1 200 OK\r\n" |
| 14462 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14463 | "Content-Length: 3\r\n\r\n" |
| 14464 | "Yes"); |
| 14465 | |
| 14466 | MockWrite writes[] = { |
| 14467 | // First round |
| 14468 | kGet, |
| 14469 | // Second round |
| 14470 | kGetAuth, |
| 14471 | // Third round |
| 14472 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14473 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14474 | kGetAuth, |
| 14475 | // Competing request |
| 14476 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14477 | }; |
| 14478 | MockRead reads[] = { |
| 14479 | // First round |
| 14480 | kServerChallenge, |
| 14481 | // Second round |
| 14482 | kServerChallenge, |
| 14483 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14484 | kServerChallenge, |
| 14485 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14486 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14487 | // Competing response |
| 14488 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14489 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14490 | StaticSocketDataProvider data_provider(reads, writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14491 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14492 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 14493 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14494 | |
| 14495 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14496 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14497 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14498 | if (rv == ERR_IO_PENDING) |
| 14499 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14500 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14501 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14502 | ASSERT_TRUE(response); |
| 14503 | EXPECT_TRUE(response->auth_challenge); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14504 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14505 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14506 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14507 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14508 | // In between rounds, another request comes in for the same domain. |
| 14509 | // It should not be able to grab the TCP socket that trans has already |
| 14510 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14511 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14512 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14513 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 14514 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14515 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14516 | // callback_compete.WaitForResult at this point would stall forever, |
| 14517 | // since the HttpNetworkTransaction does not release the request back to |
| 14518 | // the pool until after authentication completes. |
| 14519 | |
| 14520 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14521 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14522 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14523 | if (rv == ERR_IO_PENDING) |
| 14524 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14525 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14526 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14527 | ASSERT_TRUE(response); |
| 14528 | EXPECT_FALSE(response->auth_challenge); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14529 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14530 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14531 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14532 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14533 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14534 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14535 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14536 | if (rv == ERR_IO_PENDING) |
| 14537 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14538 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14539 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14540 | ASSERT_TRUE(response); |
| 14541 | EXPECT_FALSE(response->auth_challenge); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14542 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14543 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14544 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14545 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14546 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14547 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14548 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14549 | if (rv == ERR_IO_PENDING) |
| 14550 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14551 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14552 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14553 | ASSERT_TRUE(response); |
| 14554 | EXPECT_FALSE(response->auth_challenge); |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14555 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14556 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14557 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 14558 | // auth handler should transition to a DONE state in concert with the remote |
| 14559 | // server. But that's not something we can test here with a mock handler. |
| 14560 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 14561 | auth_handler->state()); |
| 14562 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14563 | // Read the body since the fourth round was successful. This will also |
| 14564 | // release the socket back to the pool. |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 14565 | scoped_refptr<IOBufferWithSize> io_buf = |
| 14566 | base::MakeRefCounted<IOBufferWithSize>(50); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14567 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14568 | if (rv == ERR_IO_PENDING) |
| 14569 | rv = callback.WaitForResult(); |
| 14570 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14571 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14572 | EXPECT_EQ(0, rv); |
| 14573 | // There are still 0 idle sockets, since the trans_compete transaction |
| 14574 | // will be handed it immediately after trans releases it to the group. |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14575 | EXPECT_EQ(0u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14576 | |
| 14577 | // The competing request can now finish. Wait for the headers and then |
| 14578 | // read the body. |
| 14579 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14580 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14581 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14582 | if (rv == ERR_IO_PENDING) |
| 14583 | rv = callback.WaitForResult(); |
| 14584 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14585 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14586 | EXPECT_EQ(0, rv); |
| 14587 | |
| 14588 | // Finally, the socket is released to the group. |
Raul Tambre | 8335a6d | 2019-02-21 16:57:43 | [diff] [blame] | 14589 | EXPECT_EQ(1u, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14590 | } |
| 14591 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14592 | // This tests the case that a request is issued via http instead of spdy after |
| 14593 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14594 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14595 | HttpRequestInfo request; |
| 14596 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14597 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14598 | request.traffic_annotation = |
| 14599 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14600 | |
| 14601 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14602 | MockWrite( |
| 14603 | "GET / HTTP/1.1\r\n" |
| 14604 | "Host: www.example.org\r\n" |
| 14605 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14606 | }; |
| 14607 | |
| 14608 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14609 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 14610 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14611 | MockRead("\r\n"), |
| 14612 | MockRead("hello world"), |
| 14613 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14614 | }; |
| 14615 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14616 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14617 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14618 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14619 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14620 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14621 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14622 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14623 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14624 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14625 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14626 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14627 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14628 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14629 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14630 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14631 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14632 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14633 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14634 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14635 | ASSERT_TRUE(response); |
| 14636 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14637 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14638 | |
| 14639 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14640 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14641 | EXPECT_EQ("hello world", response_data); |
| 14642 | |
| 14643 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14644 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14645 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14646 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 14647 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 14648 | // immediate server closing of the socket. |
| 14649 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14650 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14651 | HttpRequestInfo request; |
| 14652 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14653 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14654 | request.traffic_annotation = |
| 14655 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14656 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14657 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14658 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14659 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14660 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14661 | spdy::SpdySerializedFrame req( |
| 14662 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14663 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14664 | |
| 14665 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14666 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14667 | }; |
| 14668 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14669 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14670 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14671 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14672 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14673 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14674 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14675 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14676 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14677 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14678 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14679 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14680 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14681 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14682 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 14683 | // it gets it. This is needed since the auth handler may get destroyed |
| 14684 | // before we get a chance to query it. |
| 14685 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 14686 | public: |
| 14687 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 14688 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 14689 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14690 | |
| 14691 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14692 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 14693 | const HttpRequestInfo* request, |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14694 | CompletionOnceCallback callback, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14695 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14696 | *url_ = request->url; |
| 14697 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14698 | credentials, request, std::move(callback), auth_token); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14699 | } |
| 14700 | |
| 14701 | private: |
| 14702 | GURL* url_; |
| 14703 | }; |
| 14704 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14705 | // Test that if we cancel the transaction as the connection is completing, that |
| 14706 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14707 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14708 | // Setup everything about the connection to complete synchronously, so that |
| 14709 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 14710 | // for is the callback from the HttpStreamRequest. |
| 14711 | // Then cancel the transaction. |
| 14712 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 14713 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14714 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14715 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 14716 | MockRead(SYNCHRONOUS, "hello world"), |
| 14717 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14718 | }; |
| 14719 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14720 | HttpRequestInfo request; |
| 14721 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14722 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14723 | request.traffic_annotation = |
| 14724 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14725 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14726 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14727 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14728 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14729 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14730 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14731 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14732 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14733 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14734 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14735 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14736 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14737 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14738 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14739 | trans.reset(); // Cancel the transaction here. |
| 14740 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14741 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 14742 | } |
| 14743 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14744 | // Test that if a transaction is cancelled after receiving the headers, the |
| 14745 | // stream is drained properly and added back to the socket pool. The main |
| 14746 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 14747 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 14748 | // deleted. |
| 14749 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14750 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14751 | MockRead data_reads[] = { |
| 14752 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 14753 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 14754 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 14755 | MockRead(ASYNC, "1"), |
| 14756 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 14757 | // HttpNetworkTransaction has been deleted. |
| 14758 | MockRead(ASYNC, "2"), |
| 14759 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 14760 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14761 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14762 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14763 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14764 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14765 | |
| 14766 | { |
| 14767 | HttpRequestInfo request; |
| 14768 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14769 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14770 | request.traffic_annotation = |
| 14771 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14772 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14773 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14774 | TestCompletionCallback callback; |
| 14775 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14776 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14777 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14778 | callback.WaitForResult(); |
| 14779 | |
| 14780 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14781 | ASSERT_TRUE(response); |
| 14782 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14783 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14784 | |
| 14785 | // The transaction and HttpRequestInfo are deleted. |
| 14786 | } |
| 14787 | |
| 14788 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14789 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14790 | |
| 14791 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14792 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14793 | } |
| 14794 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14795 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14796 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14797 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14798 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14799 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14800 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14801 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14802 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14803 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14804 | HttpRequestInfo request; |
| 14805 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14806 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14807 | request.traffic_annotation = |
| 14808 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14809 | |
| 14810 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14811 | MockWrite( |
| 14812 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 14813 | "Host: www.example.org\r\n" |
| 14814 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14815 | }; |
| 14816 | |
| 14817 | MockRead data_reads1[] = { |
| 14818 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14819 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14820 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14821 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14822 | }; |
| 14823 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14824 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14825 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14826 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14827 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14828 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14829 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14830 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14831 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14832 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14833 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14834 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14835 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14836 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14837 | |
| 14838 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14839 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14840 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14841 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14842 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14843 | |
| 14844 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14845 | EXPECT_EQ(200, response->headers->response_code()); |
| 14846 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14847 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14848 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14849 | HostPortPair::FromString("myproxy:70")), |
| 14850 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14851 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14852 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14853 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14854 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14855 | |
| 14856 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14857 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14858 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14859 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14860 | } |
| 14861 | |
| 14862 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14863 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14864 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14865 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14866 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14867 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14868 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14869 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14870 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14871 | HttpRequestInfo request; |
| 14872 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14873 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14874 | request.traffic_annotation = |
| 14875 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14876 | |
| 14877 | // Since we have proxy, should try to establish tunnel. |
| 14878 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14879 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14880 | "Host: www.example.org:443\r\n" |
| 14881 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14882 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14883 | MockWrite("GET / HTTP/1.1\r\n" |
| 14884 | "Host: www.example.org\r\n" |
| 14885 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14886 | }; |
| 14887 | |
| 14888 | MockRead data_reads1[] = { |
| 14889 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14890 | |
| 14891 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14892 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14893 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14894 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14895 | }; |
| 14896 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14897 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14898 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14899 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14900 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14901 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14902 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14903 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14904 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14905 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14906 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14907 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14908 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14909 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14910 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14911 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14912 | |
| 14913 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14914 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14915 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14916 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14917 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14918 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14919 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14920 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14921 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14922 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14923 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14924 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14925 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14926 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14927 | |
| 14928 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14929 | EXPECT_EQ(200, response->headers->response_code()); |
| 14930 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14931 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14932 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14933 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14934 | HostPortPair::FromString("myproxy:70")), |
| 14935 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14936 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14937 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14938 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14939 | |
| 14940 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14941 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14942 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14943 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14944 | } |
| 14945 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14946 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 14947 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14948 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14949 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14950 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14951 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14952 | BoundTestNetLog log; |
| 14953 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14954 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14955 | |
| 14956 | HttpRequestInfo request; |
| 14957 | request.method = "GET"; |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14958 | request.url = GURL("https://[::2]:443/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14959 | request.traffic_annotation = |
| 14960 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14961 | |
| 14962 | // Since we have proxy, should try to establish tunnel. |
| 14963 | MockWrite data_writes1[] = { |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14964 | MockWrite("CONNECT [::2]:443 HTTP/1.1\r\n" |
| 14965 | "Host: [::2]:443\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14966 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 14967 | |
| 14968 | MockWrite("GET / HTTP/1.1\r\n" |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14969 | "Host: [::2]\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14970 | "Connection: keep-alive\r\n\r\n"), |
| 14971 | }; |
| 14972 | |
| 14973 | MockRead data_reads1[] = { |
| 14974 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14975 | |
| 14976 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14977 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14978 | MockRead("Content-Length: 100\r\n\r\n"), |
| 14979 | MockRead(SYNCHRONOUS, OK), |
| 14980 | }; |
| 14981 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14982 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14983 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14984 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14985 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14986 | |
| 14987 | TestCompletionCallback callback1; |
| 14988 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14989 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14990 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14991 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14992 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14993 | |
| 14994 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14995 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14996 | TestNetLogEntry::List entries; |
| 14997 | log.GetEntries(&entries); |
| 14998 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14999 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 15000 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15001 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15002 | entries, pos, |
| 15003 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 15004 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15005 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15006 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15007 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15008 | |
| 15009 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 15010 | EXPECT_EQ(200, response->headers->response_code()); |
| 15011 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 15012 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 15013 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 15014 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 15015 | HostPortPair::FromString("myproxy:70")), |
| 15016 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15017 | |
| 15018 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15019 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15020 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 15021 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 15022 | } |
| 15023 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15024 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 15025 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15026 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15027 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 15028 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15029 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15030 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15031 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15032 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15033 | HttpRequestInfo request; |
| 15034 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15035 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15036 | request.traffic_annotation = |
| 15037 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15038 | |
| 15039 | // Since we have proxy, should try to establish tunnel. |
| 15040 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15041 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 15042 | "Host: www.example.org:443\r\n" |
| 15043 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15044 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 15045 | MockWrite("GET / HTTP/1.1\r\n" |
| 15046 | "Host: www.example.org\r\n" |
| 15047 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15048 | }; |
| 15049 | |
| 15050 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15051 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15052 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15053 | }; |
| 15054 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15055 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15056 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15057 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15058 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15059 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15060 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15061 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15062 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 15063 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15064 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15065 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15066 | |
| 15067 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15068 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 15069 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 15070 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15071 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15072 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 15073 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15074 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 15075 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 15076 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 15077 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 15078 | } |
| 15079 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15080 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15081 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15082 | spdy::SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15083 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15084 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15085 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 15086 | spdy::SpdySerializedFrame resp( |
| 15087 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15088 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15089 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15090 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15091 | }; |
| 15092 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15093 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15094 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15095 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15096 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15097 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15098 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15099 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15100 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15101 | |
| 15102 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15103 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 15104 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 15105 | PRIVACY_MODE_DISABLED, |
| 15106 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 15107 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 15108 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15109 | |
| 15110 | HttpRequestInfo request; |
| 15111 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15112 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15113 | request.traffic_annotation = |
| 15114 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15115 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15116 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15117 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15118 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15119 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15120 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15121 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 15122 | } |
| 15123 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15124 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15125 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 15126 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15127 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15128 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15129 | request_info.url = GURL("https://www.example.com/"); |
| 15130 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15131 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15132 | request_info.traffic_annotation = |
| 15133 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15134 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15135 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15136 | MockWrite data_writes[] = { |
| 15137 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15138 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15139 | StaticSocketDataProvider data(base::span<MockRead>(), data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15140 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15141 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15142 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15143 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15144 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15145 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15146 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15147 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15148 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15149 | rv = callback.WaitForResult(); |
| 15150 | ASSERT_EQ(error, rv); |
| 15151 | } |
| 15152 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15153 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15154 | // Just check a grab bag of cert errors. |
| 15155 | static const int kErrors[] = { |
| 15156 | ERR_CERT_COMMON_NAME_INVALID, |
| 15157 | ERR_CERT_AUTHORITY_INVALID, |
| 15158 | ERR_CERT_DATE_INVALID, |
| 15159 | }; |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 15160 | for (size_t i = 0; i < base::size(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15161 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 15162 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15163 | } |
| 15164 | } |
| 15165 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15166 | // Ensure that a client certificate is removed from the SSL client auth |
| 15167 | // cache when: |
| 15168 | // 1) No proxy is involved. |
| 15169 | // 2) TLS False Start is disabled. |
| 15170 | // 3) The initial TLS handshake requests a client certificate. |
| 15171 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15172 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15173 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15174 | request_info.url = GURL("https://www.example.com/"); |
| 15175 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15176 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15177 | request_info.traffic_annotation = |
| 15178 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15179 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15180 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15181 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15182 | |
| 15183 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 15184 | // CertificateRequest is received for the first time, the handshake will |
| 15185 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15186 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15187 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15188 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15189 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15190 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15191 | |
| 15192 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 15193 | // False Start is not being used, the result of the SSL handshake will be |
| 15194 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 15195 | // matches the result of a server sending a handshake_failure alert, |
| 15196 | // rather than a Finished message, because it requires a client |
| 15197 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15198 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15199 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15200 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15201 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15202 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15203 | |
| 15204 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 15205 | // connection to a server fails during an SSL handshake, |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15206 | // HttpNetworkTransaction will attempt to fallback to TLSv1.2 if the previous |
| 15207 | // connection was attempted with TLSv1.3. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15208 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15209 | // requiring a client certificate, this fallback handshake should also |
| 15210 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15211 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15212 | ssl_data3.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15213 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15214 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15215 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15216 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15217 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15218 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 15219 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 15220 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 15221 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15222 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15223 | // requiring a client certificate, this fallback handshake should also |
| 15224 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15225 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15226 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15227 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15228 | StaticSocketDataProvider data4; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15229 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15230 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15231 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15232 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15233 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15234 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15235 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15236 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15237 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15238 | |
| 15239 | // Complete the SSL handshake, which should abort due to requiring a |
| 15240 | // client certificate. |
| 15241 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15242 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15243 | |
| 15244 | // Indicate that no certificate should be supplied. From the perspective |
| 15245 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15246 | // certificate, so this is the same as supply a |
| 15247 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 15248 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15249 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15250 | |
| 15251 | // Ensure the certificate was added to the client auth cache before |
| 15252 | // allowing the connection to continue restarting. |
| 15253 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15254 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15255 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15256 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15257 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15258 | |
| 15259 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15260 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15261 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15262 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15263 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15264 | |
| 15265 | // Ensure that the client certificate is removed from the cache on a |
| 15266 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15267 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15268 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15269 | } |
| 15270 | |
| 15271 | // Ensure that a client certificate is removed from the SSL client auth |
| 15272 | // cache when: |
| 15273 | // 1) No proxy is involved. |
| 15274 | // 2) TLS False Start is enabled. |
| 15275 | // 3) The initial TLS handshake requests a client certificate. |
| 15276 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15277 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15278 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15279 | request_info.url = GURL("https://www.example.com/"); |
| 15280 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15281 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15282 | request_info.traffic_annotation = |
| 15283 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15284 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15285 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15286 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15287 | |
| 15288 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 15289 | // return successfully after reading up to the peer's Certificate message. |
| 15290 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 15291 | // enqueue application data to be sent in the same packet as the |
| 15292 | // ChangeCipherSpec and Finished messages. |
| 15293 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 15294 | // called, which expects to process the peer's ChangeCipherSpec and |
| 15295 | // Finished messages. If there was an error negotiating with the peer, |
| 15296 | // such as due to the peer requiring a client certificate when none was |
| 15297 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 15298 | // called. |
| 15299 | |
| 15300 | // Like the non-False Start case, when a client certificate is requested by |
| 15301 | // the peer, the handshake is aborted during the Connect() call. |
| 15302 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15303 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15304 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15305 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15306 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15307 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15308 | |
| 15309 | // When a client certificate is supplied, Connect() will not be aborted |
| 15310 | // when the peer requests the certificate. Instead, the handshake will |
| 15311 | // artificially succeed, allowing the caller to write the HTTP request to |
| 15312 | // the socket. The handshake messages are not processed until Read() is |
| 15313 | // called, which then detects that the handshake was aborted, due to the |
| 15314 | // peer sending a handshake_failure because it requires a client |
| 15315 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15316 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15317 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15318 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15319 | MockRead data2_reads[] = { |
| 15320 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15321 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15322 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15323 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15324 | |
| 15325 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15326 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 15327 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15328 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15329 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15330 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15331 | StaticSocketDataProvider data3(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15332 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15333 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15334 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 15335 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15336 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15337 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15338 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15339 | StaticSocketDataProvider data4(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15340 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15341 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15342 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15343 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15344 | ssl_data5.cert_request_info = cert_request.get(); |
| 15345 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15346 | StaticSocketDataProvider data5(data2_reads, base::span<MockWrite>()); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15347 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 15348 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15349 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15350 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15351 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15352 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15353 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15354 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15355 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15356 | |
| 15357 | // Complete the SSL handshake, which should abort due to requiring a |
| 15358 | // client certificate. |
| 15359 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15360 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15361 | |
| 15362 | // Indicate that no certificate should be supplied. From the perspective |
| 15363 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15364 | // certificate, so this is the same as supply a |
| 15365 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 15366 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15367 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15368 | |
| 15369 | // Ensure the certificate was added to the client auth cache before |
| 15370 | // allowing the connection to continue restarting. |
| 15371 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15372 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15373 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15374 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15375 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15376 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15377 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15378 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15379 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15380 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15381 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15382 | |
| 15383 | // Ensure that the client certificate is removed from the cache on a |
| 15384 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15385 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15386 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15387 | } |
| 15388 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15389 | // Ensure that a client certificate is removed from the SSL client auth |
| 15390 | // cache when: |
| 15391 | // 1) An HTTPS proxy is involved. |
| 15392 | // 3) The HTTPS proxy requests a client certificate. |
| 15393 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 15394 | // proxy. |
| 15395 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 15396 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15397 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15398 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 15399 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15400 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15401 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15402 | |
| 15403 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15404 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15405 | |
| 15406 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 15407 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 15408 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 15409 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15410 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15411 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15412 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15413 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15414 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15415 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15416 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15417 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15418 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15419 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15420 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15421 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15422 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 15423 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15424 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15425 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15426 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15427 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15428 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15429 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15430 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15431 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15432 | requests[0].url = GURL("https://www.example.com/"); |
| 15433 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15434 | requests[0].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15435 | requests[0].traffic_annotation = |
| 15436 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15437 | |
| 15438 | requests[1].url = GURL("http://www.example.com/"); |
| 15439 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15440 | requests[1].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15441 | requests[1].traffic_annotation = |
| 15442 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15443 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 15444 | for (size_t i = 0; i < base::size(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15445 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15446 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15447 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15448 | |
| 15449 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15450 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15451 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15452 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15453 | |
| 15454 | // Complete the SSL handshake, which should abort due to requiring a |
| 15455 | // client certificate. |
| 15456 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15457 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15458 | |
| 15459 | // Indicate that no certificate should be supplied. From the perspective |
| 15460 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15461 | // certificate, so this is the same as supply a |
| 15462 | // legitimate-but-unacceptable certificate. |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 15463 | rv = trans.RestartWithCertificate(nullptr, nullptr, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15464 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15465 | |
| 15466 | // Ensure the certificate was added to the client auth cache before |
| 15467 | // allowing the connection to continue restarting. |
| 15468 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15469 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15470 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15471 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15472 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15473 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 15474 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15475 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15476 | HostPortPair("www.example.com", 443), &client_cert, |
| 15477 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15478 | |
| 15479 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 15480 | // then consume ssl_data3, which should also fail. The result code is |
| 15481 | // checked against what ssl_data3 should return. |
| 15482 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15483 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15484 | |
| 15485 | // Now that the new handshake has failed, ensure that the client |
| 15486 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15487 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15488 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15489 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15490 | HostPortPair("www.example.com", 443), &client_cert, |
| 15491 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15492 | } |
| 15493 | } |
| 15494 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15495 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15496 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15497 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15498 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15499 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15500 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15501 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15502 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15503 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15504 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15505 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15506 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15507 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15508 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15509 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15510 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 15511 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15512 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15513 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15514 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 15515 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15516 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15517 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15518 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15519 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15520 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15521 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15522 | }; |
| 15523 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15524 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15525 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15526 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15527 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15528 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15529 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15530 | HttpRequestInfo request1; |
| 15531 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15532 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15533 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15534 | request1.traffic_annotation = |
| 15535 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15536 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15537 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15538 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15539 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15540 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15541 | |
| 15542 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15543 | ASSERT_TRUE(response); |
| 15544 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15545 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15546 | |
| 15547 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15548 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15549 | EXPECT_EQ("hello!", response_data); |
| 15550 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15551 | // Preload mail.example.com into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15552 | rv = session_deps_.host_resolver->LoadIntoCache( |
| 15553 | HostPortPair("mail.example.com", 443), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15554 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15555 | |
| 15556 | HttpRequestInfo request2; |
| 15557 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15558 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15559 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15560 | request2.traffic_annotation = |
| 15561 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15562 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15563 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15564 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15565 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15566 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15567 | |
| 15568 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15569 | ASSERT_TRUE(response); |
| 15570 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15571 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15572 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15573 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15574 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15575 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15576 | } |
| 15577 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15578 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15579 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15580 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15581 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15582 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15583 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15584 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15585 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15586 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15587 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15588 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15589 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15590 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15591 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15592 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15593 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 15594 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15595 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15596 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15597 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 15598 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15599 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15600 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15601 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15602 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15603 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15604 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15605 | }; |
| 15606 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15607 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15608 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15609 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15610 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15611 | |
| 15612 | TestCompletionCallback callback; |
| 15613 | HttpRequestInfo request1; |
| 15614 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15615 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15616 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15617 | request1.traffic_annotation = |
| 15618 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15619 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15620 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15621 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15622 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15623 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15624 | |
| 15625 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15626 | ASSERT_TRUE(response); |
| 15627 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15628 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15629 | |
| 15630 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15631 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15632 | EXPECT_EQ("hello!", response_data); |
| 15633 | |
| 15634 | HttpRequestInfo request2; |
| 15635 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15636 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15637 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15638 | request2.traffic_annotation = |
| 15639 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15640 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15641 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15642 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15643 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15644 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15645 | |
| 15646 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15647 | ASSERT_TRUE(response); |
| 15648 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15649 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15650 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15651 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15652 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15653 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15654 | } |
| 15655 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15656 | // Regression test for https://crbug.com/546991. |
| 15657 | // The server might not be able to serve an IP pooled request, and might send a |
| 15658 | // 421 Misdirected Request response status to indicate this. |
| 15659 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 15660 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 15661 | // Two hosts resolve to the same IP address. |
| 15662 | const std::string ip_addr = "1.2.3.4"; |
| 15663 | IPAddress ip; |
| 15664 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 15665 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15666 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15667 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15668 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 15669 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 15670 | |
| 15671 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15672 | |
| 15673 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15674 | spdy::SpdySerializedFrame req1( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15675 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 15676 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15677 | spdy::SpdySerializedFrame req2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15678 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15679 | spdy::SpdySerializedFrame rst( |
| 15680 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15681 | MockWrite writes1[] = { |
| 15682 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 15683 | CreateMockWrite(rst, 6), |
| 15684 | }; |
| 15685 | |
| 15686 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15687 | spdy::SpdySerializedFrame resp1( |
| 15688 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15689 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15690 | spdy::SpdyHeaderBlock response_headers; |
| 15691 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 15692 | spdy::SpdySerializedFrame resp2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15693 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 15694 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15695 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15696 | |
| 15697 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15698 | SequencedSocketData data1(connect1, reads1, writes1); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15699 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15700 | |
| 15701 | AddSSLSocketData(); |
| 15702 | |
| 15703 | // Retry the second request on a second connection. |
| 15704 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15705 | spdy::SpdySerializedFrame req3( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15706 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15707 | MockWrite writes2[] = { |
| 15708 | CreateMockWrite(req3, 0), |
| 15709 | }; |
| 15710 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15711 | spdy::SpdySerializedFrame resp3( |
| 15712 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15713 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15714 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15715 | MockRead(ASYNC, 0, 3)}; |
| 15716 | |
| 15717 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15718 | SequencedSocketData data2(connect2, reads2, writes2); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15719 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15720 | |
| 15721 | AddSSLSocketData(); |
| 15722 | |
| 15723 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15724 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 15725 | HostPortPair("mail.example.com", 443), base::nullopt); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15726 | EXPECT_THAT(rv, IsOk()); |
| 15727 | |
| 15728 | HttpRequestInfo request1; |
| 15729 | request1.method = "GET"; |
| 15730 | request1.url = GURL("https://www.example.org/"); |
| 15731 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15732 | request1.traffic_annotation = |
| 15733 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15734 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15735 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15736 | TestCompletionCallback callback; |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15737 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15738 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15739 | rv = callback.WaitForResult(); |
| 15740 | EXPECT_THAT(rv, IsOk()); |
| 15741 | |
| 15742 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15743 | ASSERT_TRUE(response); |
| 15744 | ASSERT_TRUE(response->headers); |
| 15745 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15746 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15747 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15748 | std::string response_data; |
| 15749 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15750 | EXPECT_EQ("hello!", response_data); |
| 15751 | |
| 15752 | HttpRequestInfo request2; |
| 15753 | request2.method = "GET"; |
| 15754 | request2.url = GURL("https://mail.example.org/"); |
| 15755 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15756 | request2.traffic_annotation = |
| 15757 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15758 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15759 | |
| 15760 | BoundTestNetLog log; |
| 15761 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15762 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15763 | rv = callback.WaitForResult(); |
| 15764 | EXPECT_THAT(rv, IsOk()); |
| 15765 | |
| 15766 | response = trans2.GetResponseInfo(); |
| 15767 | ASSERT_TRUE(response); |
| 15768 | ASSERT_TRUE(response->headers); |
| 15769 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15770 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15771 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15772 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15773 | EXPECT_EQ("hello!", response_data); |
| 15774 | |
| 15775 | TestNetLogEntry::List entries; |
| 15776 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15777 | ExpectLogContainsSomewhere( |
| 15778 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15779 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15780 | } |
| 15781 | |
| 15782 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 15783 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 15784 | // portions of the response. |
| 15785 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 15786 | // Two hosts resolve to the same IP address. |
| 15787 | const std::string ip_addr = "1.2.3.4"; |
| 15788 | IPAddress ip; |
| 15789 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 15790 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15791 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15792 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15793 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 15794 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 15795 | |
| 15796 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15797 | |
| 15798 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15799 | spdy::SpdySerializedFrame req1( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15800 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 15801 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15802 | spdy::SpdySerializedFrame req2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15803 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15804 | spdy::SpdySerializedFrame rst( |
| 15805 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15806 | MockWrite writes1[] = { |
| 15807 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 15808 | CreateMockWrite(rst, 6), |
| 15809 | }; |
| 15810 | |
| 15811 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15812 | spdy::SpdySerializedFrame resp1( |
| 15813 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15814 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15815 | spdy::SpdyHeaderBlock response_headers; |
| 15816 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 15817 | spdy::SpdySerializedFrame resp2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15818 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 15819 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15820 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15821 | |
| 15822 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15823 | SequencedSocketData data1(connect1, reads1, writes1); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15824 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15825 | |
| 15826 | AddSSLSocketData(); |
| 15827 | |
| 15828 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 15829 | // Retry again. |
| 15830 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15831 | spdy::SpdySerializedFrame req3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15832 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15833 | MockWrite writes2[] = { |
| 15834 | CreateMockWrite(req3, 0), |
| 15835 | }; |
| 15836 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15837 | spdy::SpdySerializedFrame resp3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15838 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15839 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15840 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15841 | MockRead(ASYNC, 0, 3)}; |
| 15842 | |
| 15843 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15844 | SequencedSocketData data2(connect2, reads2, writes2); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15845 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15846 | |
| 15847 | AddSSLSocketData(); |
| 15848 | |
| 15849 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15850 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 15851 | HostPortPair("mail.example.com", 443), base::nullopt); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15852 | EXPECT_THAT(rv, IsOk()); |
| 15853 | |
| 15854 | HttpRequestInfo request1; |
| 15855 | request1.method = "GET"; |
| 15856 | request1.url = GURL("https://www.example.org/"); |
| 15857 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15858 | request1.traffic_annotation = |
| 15859 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15860 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15861 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15862 | TestCompletionCallback callback; |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15863 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15864 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15865 | rv = callback.WaitForResult(); |
| 15866 | EXPECT_THAT(rv, IsOk()); |
| 15867 | |
| 15868 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15869 | ASSERT_TRUE(response); |
| 15870 | ASSERT_TRUE(response->headers); |
| 15871 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15872 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15873 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15874 | std::string response_data; |
| 15875 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15876 | EXPECT_EQ("hello!", response_data); |
| 15877 | |
| 15878 | HttpRequestInfo request2; |
| 15879 | request2.method = "GET"; |
| 15880 | request2.url = GURL("https://mail.example.org/"); |
| 15881 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15882 | request2.traffic_annotation = |
| 15883 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15884 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15885 | |
| 15886 | BoundTestNetLog log; |
| 15887 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15888 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15889 | rv = callback.WaitForResult(); |
| 15890 | EXPECT_THAT(rv, IsOk()); |
| 15891 | |
| 15892 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 15893 | // caller. |
| 15894 | response = trans2.GetResponseInfo(); |
| 15895 | ASSERT_TRUE(response); |
| 15896 | ASSERT_TRUE(response->headers); |
| 15897 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 15898 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15899 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15900 | EXPECT_TRUE(response->ssl_info.cert); |
| 15901 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15902 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15903 | } |
| 15904 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15905 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 15906 | UseIPConnectionPoolingWithHostCacheExpiration) { |
Eric Orth | 1da75de | 2019-02-20 21:10:34 | [diff] [blame] | 15907 | // Set up HostResolver to invalidate cached entries after 1 cached resolve. |
| 15908 | session_deps_.host_resolver = |
| 15909 | std::make_unique<MockCachingHostResolver>(1 /* cache_invalidation_num */); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15910 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15911 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15912 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15913 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15914 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15915 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15916 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15917 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15918 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15919 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15920 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15921 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15922 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 15923 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15924 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15925 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15926 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 15927 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15928 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15929 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15930 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15931 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15932 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15933 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15934 | }; |
| 15935 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15936 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15937 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15938 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15939 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15940 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15941 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15942 | HttpRequestInfo request1; |
| 15943 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15944 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15945 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15946 | request1.traffic_annotation = |
| 15947 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15948 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15949 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15950 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15951 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15952 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15953 | |
| 15954 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15955 | ASSERT_TRUE(response); |
| 15956 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15957 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15958 | |
| 15959 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15960 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15961 | EXPECT_EQ("hello!", response_data); |
| 15962 | |
| 15963 | // Preload cache entries into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15964 | rv = session_deps_.host_resolver->LoadIntoCache( |
| 15965 | HostPortPair("mail.example.com", 443), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15966 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15967 | |
| 15968 | HttpRequestInfo request2; |
| 15969 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15970 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15971 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15972 | request2.traffic_annotation = |
| 15973 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15974 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15975 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15976 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15977 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15978 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15979 | |
| 15980 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15981 | ASSERT_TRUE(response); |
| 15982 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15983 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15984 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15985 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15986 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15987 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15988 | } |
| 15989 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15990 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15991 | const std::string https_url = "https://www.example.org:8080/"; |
| 15992 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15993 | |
| 15994 | // SPDY GET for HTTPS URL |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15995 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15996 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15997 | |
| 15998 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15999 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16000 | }; |
| 16001 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 16002 | spdy::SpdySerializedFrame resp1( |
| 16003 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16004 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16005 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16006 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16007 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16008 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16009 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 16010 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16011 | |
| 16012 | // HTTP GET for the HTTP URL |
| 16013 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 16014 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 16015 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16016 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 16017 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16018 | }; |
| 16019 | |
| 16020 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 16021 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 16022 | MockRead(ASYNC, 2, "hello"), |
| 16023 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16024 | }; |
| 16025 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16026 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16027 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16028 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16029 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16030 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16031 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 16032 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16033 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16034 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16035 | |
| 16036 | // Start the first transaction to set up the SpdySession |
| 16037 | HttpRequestInfo request1; |
| 16038 | request1.method = "GET"; |
| 16039 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16040 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16041 | request1.traffic_annotation = |
| 16042 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16043 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16044 | TestCompletionCallback callback1; |
| 16045 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16046 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16047 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16048 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16049 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16050 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16051 | |
| 16052 | // Now, start the HTTP request |
| 16053 | HttpRequestInfo request2; |
| 16054 | request2.method = "GET"; |
| 16055 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16056 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16057 | request2.traffic_annotation = |
| 16058 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16059 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16060 | TestCompletionCallback callback2; |
| 16061 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16062 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16063 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16064 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16065 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16066 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16067 | } |
| 16068 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16069 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 16070 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16071 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16072 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 16073 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16074 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16075 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16076 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16077 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16078 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16079 | |
| 16080 | // No data should be read from the alternative, because HTTP/1.1 is |
| 16081 | // negotiated. |
| 16082 | StaticSocketDataProvider data; |
| 16083 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16084 | |
| 16085 | // 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] | 16086 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16087 | // mocked. This way the request relies on the alternate Job. |
| 16088 | StaticSocketDataProvider data_refused; |
| 16089 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 16090 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 16091 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16092 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16093 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16094 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16095 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16096 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16097 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16098 | http_server_properties->SetHttp2AlternativeService( |
| 16099 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16100 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16101 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16102 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16103 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16104 | request.url = GURL("https://www.example.org:443"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16105 | request.traffic_annotation = |
| 16106 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16107 | TestCompletionCallback callback; |
| 16108 | |
| 16109 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16110 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16111 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16112 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16113 | } |
| 16114 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16115 | // 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] | 16116 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16117 | // succeeds, the request should succeed, even if the latter fails because |
| 16118 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16119 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16120 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 16121 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16122 | |
| 16123 | // Negotiate HTTP/1.1 with alternative. |
| 16124 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16125 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16126 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 16127 | |
| 16128 | // No data should be read from the alternative, because HTTP/1.1 is |
| 16129 | // negotiated. |
| 16130 | StaticSocketDataProvider data; |
| 16131 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16132 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16133 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16134 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16135 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16136 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 16137 | |
| 16138 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16139 | MockWrite("GET / HTTP/1.1\r\n" |
| 16140 | "Host: www.example.org\r\n" |
| 16141 | "Connection: keep-alive\r\n\r\n"), |
| 16142 | MockWrite("GET /second HTTP/1.1\r\n" |
| 16143 | "Host: www.example.org\r\n" |
| 16144 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16145 | }; |
| 16146 | |
| 16147 | MockRead http_reads[] = { |
| 16148 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16149 | MockRead("Content-Type: text/html\r\n"), |
| 16150 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16151 | MockRead("foobar"), |
| 16152 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16153 | MockRead("Content-Type: text/html\r\n"), |
| 16154 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16155 | MockRead("another"), |
| 16156 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16157 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16158 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16159 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16160 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16161 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16162 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16163 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16164 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16165 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16166 | http_server_properties->SetHttp2AlternativeService( |
| 16167 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16168 | |
| 16169 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 16170 | HttpRequestInfo request1; |
| 16171 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16172 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16173 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16174 | request1.traffic_annotation = |
| 16175 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16176 | TestCompletionCallback callback1; |
| 16177 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16178 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16179 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16180 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16181 | |
| 16182 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16183 | ASSERT_TRUE(response1); |
| 16184 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16185 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 16186 | |
| 16187 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16188 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16189 | EXPECT_EQ("foobar", response_data1); |
| 16190 | |
| 16191 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 16192 | // for alternative service. |
| 16193 | EXPECT_TRUE( |
| 16194 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 16195 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16196 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16197 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16198 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16199 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 16200 | HttpRequestInfo request2; |
| 16201 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16202 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16203 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16204 | request2.traffic_annotation = |
| 16205 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16206 | TestCompletionCallback callback2; |
| 16207 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16208 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16209 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16210 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16211 | |
| 16212 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16213 | ASSERT_TRUE(response2); |
| 16214 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16215 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 16216 | |
| 16217 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16218 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16219 | EXPECT_EQ("another", response_data2); |
| 16220 | } |
| 16221 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16222 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 16223 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 16224 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16225 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16226 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16227 | HostPortPair alternative("alternative.example.org", 443); |
| 16228 | std::string origin_url = "https://origin.example.org:443"; |
| 16229 | std::string alternative_url = "https://alternative.example.org:443"; |
| 16230 | |
| 16231 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 16232 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16233 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16234 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16235 | |
| 16236 | // HTTP/1.1 data for |request1| and |request2|. |
| 16237 | MockWrite http_writes[] = { |
| 16238 | MockWrite( |
| 16239 | "GET / HTTP/1.1\r\n" |
| 16240 | "Host: alternative.example.org\r\n" |
| 16241 | "Connection: keep-alive\r\n\r\n"), |
| 16242 | MockWrite( |
| 16243 | "GET / HTTP/1.1\r\n" |
| 16244 | "Host: alternative.example.org\r\n" |
| 16245 | "Connection: keep-alive\r\n\r\n"), |
| 16246 | }; |
| 16247 | |
| 16248 | MockRead http_reads[] = { |
| 16249 | MockRead( |
| 16250 | "HTTP/1.1 200 OK\r\n" |
| 16251 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16252 | "Content-Length: 40\r\n\r\n" |
| 16253 | "first HTTP/1.1 response from alternative"), |
| 16254 | MockRead( |
| 16255 | "HTTP/1.1 200 OK\r\n" |
| 16256 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16257 | "Content-Length: 41\r\n\r\n" |
| 16258 | "second HTTP/1.1 response from alternative"), |
| 16259 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16260 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16261 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16262 | |
| 16263 | // This test documents that an alternate Job should not pool to an already |
| 16264 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16265 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16266 | StaticSocketDataProvider data_refused; |
| 16267 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 16268 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 16269 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16270 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16271 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16272 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16273 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16274 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16275 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16276 | http_server_properties->SetHttp2AlternativeService( |
| 16277 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16278 | |
| 16279 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16280 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16281 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16282 | request1.method = "GET"; |
| 16283 | request1.url = GURL(alternative_url); |
| 16284 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16285 | request1.traffic_annotation = |
| 16286 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16287 | TestCompletionCallback callback1; |
| 16288 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16289 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16290 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16291 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16292 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16293 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16294 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16295 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16296 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 16297 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16298 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16299 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 16300 | |
| 16301 | // Request for origin.example.org, which has an alternative service. This |
| 16302 | // will start two Jobs: the alternative looks for connections to pool to, |
| 16303 | // 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] | 16304 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16305 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16306 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16307 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16308 | request2.method = "GET"; |
| 16309 | request2.url = GURL(origin_url); |
| 16310 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16311 | request2.traffic_annotation = |
| 16312 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16313 | TestCompletionCallback callback2; |
| 16314 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16315 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16316 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16317 | |
| 16318 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 16319 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16320 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16321 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16322 | request3.method = "GET"; |
| 16323 | request3.url = GURL(alternative_url); |
| 16324 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16325 | request3.traffic_annotation = |
| 16326 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16327 | TestCompletionCallback callback3; |
| 16328 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16329 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16330 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16331 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16332 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16333 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16334 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16335 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16336 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 16337 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16338 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16339 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 16340 | } |
| 16341 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16342 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16343 | const std::string https_url = "https://www.example.org:8080/"; |
| 16344 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16345 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16346 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16347 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16348 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16349 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16350 | const HostPortPair host_port_pair("www.example.org", 8080); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16351 | spdy::SpdySerializedFrame connect( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 16352 | spdy_util_.ConstructSpdyConnect(nullptr, 0, 1, LOWEST, host_port_pair)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16353 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16354 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16355 | spdy::SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 16356 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 16357 | |
| 16358 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16359 | spdy::SpdyHeaderBlock req2_block; |
| 16360 | req2_block[spdy::kHttp2MethodHeader] = "GET"; |
| 16361 | req2_block[spdy::kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 16362 | req2_block[spdy::kHttp2SchemeHeader] = "http"; |
| 16363 | req2_block[spdy::kHttp2PathHeader] = "/"; |
| 16364 | spdy::SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16365 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16366 | |
| 16367 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16368 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 16369 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16370 | }; |
| 16371 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16372 | spdy::SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16373 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16374 | spdy::SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16375 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16376 | spdy::SpdySerializedFrame body1( |
| 16377 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 16378 | spdy::SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16379 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16380 | spdy::SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16381 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 16382 | spdy::SpdySerializedFrame resp2( |
| 16383 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 3)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16384 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16385 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16386 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16387 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16388 | CreateMockRead(wrapped_resp1, 4), |
| 16389 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16390 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16391 | CreateMockRead(resp2, 8), |
| 16392 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16393 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 16394 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16395 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16396 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16397 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 16398 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16399 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16400 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16401 | ProxyResolutionService::CreateFixedFromPacResult( |
| 16402 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 16403 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16404 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16405 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16406 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16407 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16408 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16409 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16410 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16411 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16412 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16413 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16414 | |
| 16415 | // Start the first transaction to set up the SpdySession |
| 16416 | HttpRequestInfo request1; |
| 16417 | request1.method = "GET"; |
| 16418 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16419 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16420 | request1.traffic_annotation = |
| 16421 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16422 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16423 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16424 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16425 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16426 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16427 | data1.RunUntilPaused(); |
| 16428 | base::RunLoop().RunUntilIdle(); |
| 16429 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16430 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16431 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16432 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16433 | LoadTimingInfo load_timing_info1; |
| 16434 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 16435 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 16436 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 16437 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16438 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16439 | HttpRequestInfo request2; |
| 16440 | request2.method = "GET"; |
| 16441 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16442 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16443 | request2.traffic_annotation = |
| 16444 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16445 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16446 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16447 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16448 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16449 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16450 | data1.RunUntilPaused(); |
| 16451 | base::RunLoop().RunUntilIdle(); |
| 16452 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16453 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16454 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16455 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16456 | |
| 16457 | LoadTimingInfo load_timing_info2; |
| 16458 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 16459 | // The established SPDY sessions is considered reused by the HTTP request. |
| 16460 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 16461 | // HTTP requests over a SPDY session should have a different connection |
| 16462 | // socket_log_id than requests over a tunnel. |
| 16463 | 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] | 16464 | } |
| 16465 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16466 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 16467 | // that we do not pool other origins that resolve to the same IP when |
| 16468 | // the certificate does not match the new origin. |
| 16469 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16470 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16471 | const std::string url1 = "http://www.example.org/"; |
| 16472 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16473 | const std::string ip_addr = "1.2.3.4"; |
| 16474 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16475 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16476 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16477 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16478 | // SPDY GET for HTTP URL (through SPDY proxy) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16479 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16480 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16481 | spdy::SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16482 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16483 | |
| 16484 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16485 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16486 | }; |
| 16487 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 16488 | spdy::SpdySerializedFrame resp1( |
| 16489 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16490 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16491 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16492 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 16493 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16494 | }; |
| 16495 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16496 | SequencedSocketData data1(reads1, writes1); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 16497 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 16498 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16499 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 16500 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16501 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16502 | |
| 16503 | // SPDY GET for HTTPS URL (direct) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16504 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16505 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16506 | |
| 16507 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16508 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16509 | }; |
| 16510 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16511 | spdy::SpdySerializedFrame resp2( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 16512 | spdy_util_secure.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16513 | spdy::SpdySerializedFrame body2( |
| 16514 | spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16515 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16516 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16517 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16518 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16519 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16520 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16521 | |
| 16522 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 16523 | // all others direct. |
| 16524 | ProxyConfig proxy_config; |
| 16525 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16526 | session_deps_.proxy_resolution_service = |
| 16527 | std::make_unique<ProxyResolutionService>( |
| 16528 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 16529 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 16530 | nullptr, nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16531 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16532 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16533 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16534 | // Load a valid cert. Note, that this does not need to |
| 16535 | // be valid for proxy because the MockSSLClientSocket does |
| 16536 | // not actually verify it. But SpdySession will use this |
| 16537 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 16538 | ssl1.ssl_info.cert = |
| 16539 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 16540 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16541 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16542 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16543 | |
| 16544 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16545 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16546 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16547 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16548 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16549 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16550 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16551 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16552 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16553 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16554 | |
| 16555 | // Start the first transaction to set up the SpdySession |
| 16556 | HttpRequestInfo request1; |
| 16557 | request1.method = "GET"; |
| 16558 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16559 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16560 | request1.traffic_annotation = |
| 16561 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16562 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16563 | TestCompletionCallback callback1; |
| 16564 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16565 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16566 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16567 | data1.RunUntilPaused(); |
| 16568 | base::RunLoop().RunUntilIdle(); |
| 16569 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16570 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16571 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16572 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16573 | |
| 16574 | // Now, start the HTTP request |
| 16575 | HttpRequestInfo request2; |
| 16576 | request2.method = "GET"; |
| 16577 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16578 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16579 | request2.traffic_annotation = |
| 16580 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16581 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16582 | TestCompletionCallback callback2; |
| 16583 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16584 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16585 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16586 | |
| 16587 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16588 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16589 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16590 | } |
| 16591 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16592 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 16593 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 16594 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 16595 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16596 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16597 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16598 | |
| 16599 | MockRead reads1[] = { |
| 16600 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 16601 | }; |
| 16602 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16603 | SequencedSocketData data1(reads1, base::span<MockWrite>()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16604 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16605 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16606 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16607 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16608 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16609 | }; |
| 16610 | |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 16611 | spdy::SpdySerializedFrame resp2( |
| 16612 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16613 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16614 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16615 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 16616 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16617 | }; |
| 16618 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16619 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16620 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16621 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16622 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16623 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16624 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16625 | |
| 16626 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16627 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16628 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16629 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16630 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16631 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16632 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16633 | |
| 16634 | // Start the first transaction to set up the SpdySession and verify that |
| 16635 | // connection was closed. |
| 16636 | HttpRequestInfo request1; |
| 16637 | request1.method = "GET"; |
| 16638 | request1.url = GURL(https_url); |
| 16639 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16640 | request1.traffic_annotation = |
| 16641 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16642 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16643 | TestCompletionCallback callback1; |
| 16644 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16645 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16646 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16647 | |
| 16648 | // Now, start the second request and make sure it succeeds. |
| 16649 | HttpRequestInfo request2; |
| 16650 | request2.method = "GET"; |
| 16651 | request2.url = GURL(https_url); |
| 16652 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16653 | request2.traffic_annotation = |
| 16654 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16655 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16656 | TestCompletionCallback callback2; |
| 16657 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16658 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16659 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16660 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16661 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16662 | } |
| 16663 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16664 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16665 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16666 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16667 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16668 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16669 | |
| 16670 | // Use two different hosts with different IPs so they don't get pooled. |
| 16671 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 16672 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16673 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16674 | |
| 16675 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16676 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16677 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16678 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16679 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16680 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16681 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16682 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16683 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16684 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16685 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16686 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16687 | spdy::SpdySerializedFrame host1_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 16688 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16689 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16690 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16691 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16692 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16693 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16694 | }; |
| 16695 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16696 | // Use a separate test instance for the separate SpdySession that will be |
| 16697 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16698 | SpdyTestUtil spdy_util_2; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16699 | SequencedSocketData spdy1_data(spdy1_reads, spdy1_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 16700 | session_deps_.socket_factory->AddSocketDataProvider(&spdy1_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16701 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16702 | spdy::SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16703 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16704 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16705 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16706 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16707 | spdy::SpdySerializedFrame host2_resp( |
Raul Tambre | 94493c65 | 2019-03-11 17:18:35 | [diff] [blame^] | 16708 | spdy_util_2.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16709 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16710 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16711 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16712 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16713 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16714 | }; |
| 16715 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16716 | SequencedSocketData spdy2_data(spdy2_reads, spdy2_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 16717 | session_deps_.socket_factory->AddSocketDataProvider(&spdy2_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16718 | |
| 16719 | MockWrite http_write[] = { |
| 16720 | MockWrite("GET / HTTP/1.1\r\n" |
| 16721 | "Host: www.a.com\r\n" |
| 16722 | "Connection: keep-alive\r\n\r\n"), |
| 16723 | }; |
| 16724 | |
| 16725 | MockRead http_read[] = { |
| 16726 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16727 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 16728 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16729 | MockRead("hello!"), |
| 16730 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16731 | StaticSocketDataProvider http_data(http_read, http_write); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16732 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16733 | |
| 16734 | HostPortPair host_port_pair_a("www.a.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16735 | SpdySessionKey spdy_session_key_a( |
| 16736 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16737 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16738 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16739 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16740 | |
| 16741 | TestCompletionCallback callback; |
| 16742 | HttpRequestInfo request1; |
| 16743 | request1.method = "GET"; |
| 16744 | request1.url = GURL("https://www.a.com/"); |
| 16745 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16746 | request1.traffic_annotation = |
| 16747 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16748 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16749 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16750 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16751 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16752 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16753 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16754 | |
| 16755 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16756 | ASSERT_TRUE(response); |
| 16757 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16758 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16759 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16760 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16761 | |
| 16762 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16763 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16764 | EXPECT_EQ("hello!", response_data); |
| 16765 | trans.reset(); |
| 16766 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16767 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16768 | |
| 16769 | HostPortPair host_port_pair_b("www.b.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16770 | SpdySessionKey spdy_session_key_b( |
| 16771 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16772 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16773 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16774 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16775 | HttpRequestInfo request2; |
| 16776 | request2.method = "GET"; |
| 16777 | request2.url = GURL("https://www.b.com/"); |
| 16778 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16779 | request2.traffic_annotation = |
| 16780 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16781 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16782 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16783 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16784 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16785 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16786 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16787 | |
| 16788 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16789 | ASSERT_TRUE(response); |
| 16790 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16791 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16792 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16793 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16794 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16795 | EXPECT_EQ("hello!", response_data); |
| 16796 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16797 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16798 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16799 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16800 | |
| 16801 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16802 | SpdySessionKey spdy_session_key_a1( |
| 16803 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16804 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16805 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16806 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16807 | HttpRequestInfo request3; |
| 16808 | request3.method = "GET"; |
| 16809 | request3.url = GURL("http://www.a.com/"); |
| 16810 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16811 | request3.traffic_annotation = |
| 16812 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16813 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16814 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16815 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16816 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16817 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16818 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16819 | |
| 16820 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16821 | ASSERT_TRUE(response); |
| 16822 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16823 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 16824 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16825 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16826 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16827 | EXPECT_EQ("hello!", response_data); |
| 16828 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16829 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16830 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16831 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16832 | } |
| 16833 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16834 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16835 | HttpRequestInfo request; |
| 16836 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16837 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16838 | request.traffic_annotation = |
| 16839 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16840 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16841 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16842 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16843 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16844 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16845 | StaticSocketDataProvider data; |
| 16846 | data.set_connect_data(mock_connect); |
| 16847 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16848 | |
| 16849 | TestCompletionCallback callback; |
| 16850 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16851 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16852 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16853 | |
| 16854 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16855 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16856 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16857 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16858 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16859 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16860 | |
| 16861 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16862 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16863 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16864 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16865 | |
| 16866 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16867 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16868 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16869 | } |
| 16870 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16871 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16872 | HttpRequestInfo request; |
| 16873 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16874 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16875 | request.traffic_annotation = |
| 16876 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16877 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16878 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16879 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16880 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16881 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16882 | StaticSocketDataProvider data; |
| 16883 | data.set_connect_data(mock_connect); |
| 16884 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16885 | |
| 16886 | TestCompletionCallback callback; |
| 16887 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16888 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16889 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16890 | |
| 16891 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16892 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16893 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16894 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16895 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16896 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16897 | |
| 16898 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16899 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16900 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16901 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16902 | |
| 16903 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16904 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16905 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16906 | } |
| 16907 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16908 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16909 | HttpRequestInfo request; |
| 16910 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16911 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16912 | request.traffic_annotation = |
| 16913 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16914 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16915 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16916 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16917 | |
| 16918 | MockWrite data_writes[] = { |
| 16919 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16920 | }; |
| 16921 | MockRead data_reads[] = { |
| 16922 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16923 | }; |
| 16924 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16925 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16926 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16927 | |
| 16928 | TestCompletionCallback callback; |
| 16929 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16930 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16931 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16932 | |
| 16933 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16934 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16935 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16936 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16937 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16938 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16939 | } |
| 16940 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16941 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16942 | HttpRequestInfo request; |
| 16943 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16944 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16945 | request.traffic_annotation = |
| 16946 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16947 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16948 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16949 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16950 | |
| 16951 | MockWrite data_writes[] = { |
| 16952 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 16953 | }; |
| 16954 | MockRead data_reads[] = { |
| 16955 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16956 | }; |
| 16957 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16958 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16959 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16960 | |
| 16961 | TestCompletionCallback callback; |
| 16962 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16963 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16964 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16965 | |
| 16966 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16967 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16968 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16969 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16970 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16971 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16972 | } |
| 16973 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16974 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16975 | HttpRequestInfo request; |
| 16976 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16977 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16978 | request.traffic_annotation = |
| 16979 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16980 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16981 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16982 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16983 | |
| 16984 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16985 | MockWrite( |
| 16986 | "GET / HTTP/1.1\r\n" |
| 16987 | "Host: www.example.org\r\n" |
| 16988 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16989 | }; |
| 16990 | MockRead data_reads[] = { |
| 16991 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16992 | }; |
| 16993 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16994 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16995 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16996 | |
| 16997 | TestCompletionCallback callback; |
| 16998 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16999 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17000 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17001 | |
| 17002 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17003 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17004 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17005 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17006 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17007 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 17008 | } |
| 17009 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17010 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17011 | HttpRequestInfo request; |
| 17012 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17013 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17014 | request.traffic_annotation = |
| 17015 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17016 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17017 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17018 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17019 | |
| 17020 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17021 | MockWrite( |
| 17022 | "GET / HTTP/1.1\r\n" |
| 17023 | "Host: www.example.org\r\n" |
| 17024 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17025 | }; |
| 17026 | MockRead data_reads[] = { |
| 17027 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 17028 | }; |
| 17029 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17030 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17031 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17032 | |
| 17033 | TestCompletionCallback callback; |
| 17034 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17035 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17036 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17037 | |
| 17038 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17039 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17040 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17041 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17042 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17043 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 17044 | } |
| 17045 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17046 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17047 | HttpRequestInfo request; |
| 17048 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17049 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17050 | request.extra_headers.SetHeader("X-Foo", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17051 | request.traffic_annotation = |
| 17052 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17053 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17054 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17055 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17056 | |
| 17057 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17058 | MockWrite( |
| 17059 | "GET / HTTP/1.1\r\n" |
| 17060 | "Host: www.example.org\r\n" |
| 17061 | "Connection: keep-alive\r\n" |
| 17062 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17063 | }; |
| 17064 | MockRead data_reads[] = { |
| 17065 | MockRead("HTTP/1.1 200 OK\r\n" |
| 17066 | "Content-Length: 5\r\n\r\n" |
| 17067 | "hello"), |
| 17068 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 17069 | }; |
| 17070 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17071 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17072 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17073 | |
| 17074 | TestCompletionCallback callback; |
| 17075 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17076 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17077 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17078 | |
| 17079 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17080 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17081 | |
| 17082 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17083 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 17084 | std::string foo; |
| 17085 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 17086 | EXPECT_EQ("bar", foo); |
| 17087 | } |
| 17088 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17089 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 17090 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17091 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17092 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17093 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17094 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17095 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17096 | |
| 17097 | // Set up SSL request. |
| 17098 | |
| 17099 | HttpRequestInfo ssl_request; |
| 17100 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17101 | ssl_request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17102 | ssl_request.traffic_annotation = |
| 17103 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17104 | |
| 17105 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17106 | MockWrite( |
| 17107 | "GET / HTTP/1.1\r\n" |
| 17108 | "Host: www.example.org\r\n" |
| 17109 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17110 | }; |
| 17111 | MockRead ssl_reads[] = { |
| 17112 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17113 | MockRead("Content-Length: 11\r\n\r\n"), |
| 17114 | MockRead("hello world"), |
| 17115 | MockRead(SYNCHRONOUS, OK), |
| 17116 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17117 | StaticSocketDataProvider ssl_data(ssl_reads, ssl_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17118 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17119 | |
| 17120 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17121 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17122 | |
| 17123 | // Set up HTTP request. |
| 17124 | |
| 17125 | HttpRequestInfo http_request; |
| 17126 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17127 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17128 | http_request.traffic_annotation = |
| 17129 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17130 | |
| 17131 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17132 | MockWrite( |
| 17133 | "GET / HTTP/1.1\r\n" |
| 17134 | "Host: www.example.org\r\n" |
| 17135 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17136 | }; |
| 17137 | MockRead http_reads[] = { |
| 17138 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17139 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17140 | MockRead("falafel"), |
| 17141 | MockRead(SYNCHRONOUS, OK), |
| 17142 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17143 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17144 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17145 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17146 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17147 | |
| 17148 | // Start the SSL request. |
| 17149 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17150 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17151 | ASSERT_EQ(ERR_IO_PENDING, |
| 17152 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 17153 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17154 | |
| 17155 | // Start the HTTP request. Pool should stall. |
| 17156 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17157 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17158 | ASSERT_EQ(ERR_IO_PENDING, |
| 17159 | http_trans.Start(&http_request, http_callback.callback(), |
| 17160 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17161 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17162 | |
| 17163 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17164 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17165 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17166 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17167 | EXPECT_EQ("hello world", response_data); |
| 17168 | |
| 17169 | // The SSL socket should automatically be closed, so the HTTP request can |
| 17170 | // start. |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 17171 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17172 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17173 | |
| 17174 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17175 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17176 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17177 | EXPECT_EQ("falafel", response_data); |
| 17178 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17179 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17180 | } |
| 17181 | |
| 17182 | // Tests that when a SSL connection is established but there's no corresponding |
| 17183 | // request that needs it, the new socket is closed if the transport socket pool |
| 17184 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17185 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17186 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17187 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17188 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17189 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17190 | |
| 17191 | // Set up an ssl request. |
| 17192 | |
| 17193 | HttpRequestInfo ssl_request; |
| 17194 | ssl_request.method = "GET"; |
| 17195 | ssl_request.url = GURL("https://www.foopy.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17196 | ssl_request.traffic_annotation = |
| 17197 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17198 | |
| 17199 | // No data will be sent on the SSL socket. |
| 17200 | StaticSocketDataProvider ssl_data; |
| 17201 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17202 | |
| 17203 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17204 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17205 | |
| 17206 | // Set up HTTP request. |
| 17207 | |
| 17208 | HttpRequestInfo http_request; |
| 17209 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17210 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17211 | http_request.traffic_annotation = |
| 17212 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17213 | |
| 17214 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17215 | MockWrite( |
| 17216 | "GET / HTTP/1.1\r\n" |
| 17217 | "Host: www.example.org\r\n" |
| 17218 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17219 | }; |
| 17220 | MockRead http_reads[] = { |
| 17221 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17222 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17223 | MockRead("falafel"), |
| 17224 | MockRead(SYNCHRONOUS, OK), |
| 17225 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17226 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17227 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17228 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17229 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17230 | |
| 17231 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 17232 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 17233 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 17234 | http_stream_factory->PreconnectStreams(1, ssl_request); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 17235 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17236 | |
| 17237 | // Start the HTTP request. Pool should stall. |
| 17238 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17239 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17240 | ASSERT_EQ(ERR_IO_PENDING, |
| 17241 | http_trans.Start(&http_request, http_callback.callback(), |
| 17242 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17243 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17244 | |
| 17245 | // The SSL connection will automatically be closed once the connection is |
| 17246 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17247 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17248 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17249 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17250 | EXPECT_EQ("falafel", response_data); |
| 17251 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17252 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17253 | } |
| 17254 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17255 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17256 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17257 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17258 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17259 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17260 | |
| 17261 | HttpRequestInfo request; |
| 17262 | request.method = "POST"; |
| 17263 | request.url = GURL("http://www.foo.com/"); |
| 17264 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17265 | request.traffic_annotation = |
| 17266 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17267 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17268 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17269 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17270 | // Send headers successfully, but get an error while sending the body. |
| 17271 | MockWrite data_writes[] = { |
| 17272 | MockWrite("POST / HTTP/1.1\r\n" |
| 17273 | "Host: www.foo.com\r\n" |
| 17274 | "Connection: keep-alive\r\n" |
| 17275 | "Content-Length: 3\r\n\r\n"), |
| 17276 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17277 | }; |
| 17278 | |
| 17279 | MockRead data_reads[] = { |
| 17280 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17281 | MockRead("hello world"), |
| 17282 | MockRead(SYNCHRONOUS, OK), |
| 17283 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17284 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17285 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17286 | |
| 17287 | TestCompletionCallback callback; |
| 17288 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17289 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17290 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17291 | |
| 17292 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17293 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17294 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17295 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17296 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17297 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17298 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17299 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17300 | |
| 17301 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17302 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17303 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17304 | EXPECT_EQ("hello world", response_data); |
| 17305 | } |
| 17306 | |
| 17307 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 17308 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17309 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17310 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17311 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17312 | MockWrite data_writes[] = { |
| 17313 | MockWrite("GET / HTTP/1.1\r\n" |
| 17314 | "Host: www.foo.com\r\n" |
| 17315 | "Connection: keep-alive\r\n\r\n"), |
| 17316 | MockWrite("POST / HTTP/1.1\r\n" |
| 17317 | "Host: www.foo.com\r\n" |
| 17318 | "Connection: keep-alive\r\n" |
| 17319 | "Content-Length: 3\r\n\r\n"), |
| 17320 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17321 | }; |
| 17322 | |
| 17323 | MockRead data_reads[] = { |
| 17324 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 17325 | "Content-Length: 14\r\n\r\n"), |
| 17326 | MockRead("first response"), |
| 17327 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 17328 | "Content-Length: 15\r\n\r\n"), |
| 17329 | MockRead("second response"), |
| 17330 | MockRead(SYNCHRONOUS, OK), |
| 17331 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17332 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17333 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17334 | |
| 17335 | TestCompletionCallback callback; |
| 17336 | HttpRequestInfo request1; |
| 17337 | request1.method = "GET"; |
| 17338 | request1.url = GURL("http://www.foo.com/"); |
| 17339 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17340 | request1.traffic_annotation = |
| 17341 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17342 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17343 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17344 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17345 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17346 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17347 | |
| 17348 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17349 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17350 | |
| 17351 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17352 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17353 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17354 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17355 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 17356 | |
| 17357 | std::string response_data1; |
| 17358 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17359 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17360 | EXPECT_EQ("first response", response_data1); |
| 17361 | // Delete the transaction to release the socket back into the socket pool. |
| 17362 | trans1.reset(); |
| 17363 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17364 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17365 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17366 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17367 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17368 | |
| 17369 | HttpRequestInfo request2; |
| 17370 | request2.method = "POST"; |
| 17371 | request2.url = GURL("http://www.foo.com/"); |
| 17372 | request2.upload_data_stream = &upload_data_stream; |
| 17373 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17374 | request2.traffic_annotation = |
| 17375 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17376 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17377 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17378 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17379 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17380 | |
| 17381 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17382 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17383 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17384 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17385 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17386 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17387 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17388 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 17389 | |
| 17390 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17391 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17392 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17393 | EXPECT_EQ("second response", response_data2); |
| 17394 | } |
| 17395 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17396 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17397 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17398 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17399 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17400 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17401 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17402 | |
| 17403 | HttpRequestInfo request; |
| 17404 | request.method = "POST"; |
| 17405 | request.url = GURL("http://www.foo.com/"); |
| 17406 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17407 | request.traffic_annotation = |
| 17408 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17409 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17410 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17411 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17412 | // Send headers successfully, but get an error while sending the body. |
| 17413 | MockWrite data_writes[] = { |
| 17414 | MockWrite("POST / HTTP/1.1\r\n" |
| 17415 | "Host: www.foo.com\r\n" |
| 17416 | "Connection: keep-alive\r\n" |
| 17417 | "Content-Length: 3\r\n\r\n" |
| 17418 | "fo"), |
| 17419 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17420 | }; |
| 17421 | |
| 17422 | MockRead data_reads[] = { |
| 17423 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17424 | MockRead("hello world"), |
| 17425 | MockRead(SYNCHRONOUS, OK), |
| 17426 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17427 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17428 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17429 | |
| 17430 | TestCompletionCallback callback; |
| 17431 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17432 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17433 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17434 | |
| 17435 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17436 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17437 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17438 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17439 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17440 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17441 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17442 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17443 | |
| 17444 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17445 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17446 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17447 | EXPECT_EQ("hello world", response_data); |
| 17448 | } |
| 17449 | |
| 17450 | // This tests the more common case than the previous test, where headers and |
| 17451 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17452 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17453 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17454 | |
| 17455 | HttpRequestInfo request; |
| 17456 | request.method = "POST"; |
| 17457 | request.url = GURL("http://www.foo.com/"); |
| 17458 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17459 | request.traffic_annotation = |
| 17460 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17461 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17462 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17463 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17464 | // Send headers successfully, but get an error while sending the body. |
| 17465 | MockWrite data_writes[] = { |
| 17466 | MockWrite("POST / HTTP/1.1\r\n" |
| 17467 | "Host: www.foo.com\r\n" |
| 17468 | "Connection: keep-alive\r\n" |
| 17469 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17470 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17471 | }; |
| 17472 | |
| 17473 | MockRead data_reads[] = { |
| 17474 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17475 | MockRead("hello world"), |
| 17476 | MockRead(SYNCHRONOUS, OK), |
| 17477 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17478 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17479 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17480 | |
| 17481 | TestCompletionCallback callback; |
| 17482 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17483 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17484 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17485 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 17486 | // they can't be merged with the body in a single send. Not currently |
| 17487 | // necessary since a chunked body is never merged with headers, but this makes |
| 17488 | // the test more future proof. |
| 17489 | base::RunLoop().RunUntilIdle(); |
| 17490 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17491 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17492 | |
| 17493 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17494 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17495 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17496 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17497 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17498 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17499 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17500 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17501 | |
| 17502 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17503 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17504 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17505 | EXPECT_EQ("hello world", response_data); |
| 17506 | } |
| 17507 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17508 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17509 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17510 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17511 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17512 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17513 | |
| 17514 | HttpRequestInfo request; |
| 17515 | request.method = "POST"; |
| 17516 | request.url = GURL("http://www.foo.com/"); |
| 17517 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17518 | request.traffic_annotation = |
| 17519 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17520 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17521 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17522 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17523 | |
| 17524 | MockWrite data_writes[] = { |
| 17525 | MockWrite("POST / HTTP/1.1\r\n" |
| 17526 | "Host: www.foo.com\r\n" |
| 17527 | "Connection: keep-alive\r\n" |
| 17528 | "Content-Length: 3\r\n\r\n"), |
| 17529 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17530 | }; |
| 17531 | |
| 17532 | MockRead data_reads[] = { |
| 17533 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17534 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17535 | MockRead("hello world"), |
| 17536 | MockRead(SYNCHRONOUS, OK), |
| 17537 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17538 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17539 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17540 | |
| 17541 | TestCompletionCallback callback; |
| 17542 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17543 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17544 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17545 | |
| 17546 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17547 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17548 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17549 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17550 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17551 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17552 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17553 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17554 | |
| 17555 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17556 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17557 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17558 | EXPECT_EQ("hello world", response_data); |
| 17559 | } |
| 17560 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17561 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17562 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17563 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17564 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17565 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17566 | |
| 17567 | HttpRequestInfo request; |
| 17568 | request.method = "POST"; |
| 17569 | request.url = GURL("http://www.foo.com/"); |
| 17570 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17571 | request.traffic_annotation = |
| 17572 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17573 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17574 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17575 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17576 | // Send headers successfully, but get an error while sending the body. |
| 17577 | MockWrite data_writes[] = { |
| 17578 | MockWrite("POST / HTTP/1.1\r\n" |
| 17579 | "Host: www.foo.com\r\n" |
| 17580 | "Connection: keep-alive\r\n" |
| 17581 | "Content-Length: 3\r\n\r\n"), |
| 17582 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17583 | }; |
| 17584 | |
| 17585 | MockRead data_reads[] = { |
| 17586 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 17587 | MockRead("hello world"), |
| 17588 | MockRead(SYNCHRONOUS, OK), |
| 17589 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17590 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17591 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17592 | |
| 17593 | TestCompletionCallback callback; |
| 17594 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17595 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17596 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17597 | |
| 17598 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17599 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17600 | } |
| 17601 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17602 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17603 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17604 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17605 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17606 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17607 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17608 | |
| 17609 | HttpRequestInfo request; |
| 17610 | request.method = "POST"; |
| 17611 | request.url = GURL("http://www.foo.com/"); |
| 17612 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17613 | request.traffic_annotation = |
| 17614 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17615 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17616 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17617 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17618 | // Send headers successfully, but get an error while sending the body. |
| 17619 | MockWrite data_writes[] = { |
| 17620 | MockWrite("POST / HTTP/1.1\r\n" |
| 17621 | "Host: www.foo.com\r\n" |
| 17622 | "Connection: keep-alive\r\n" |
| 17623 | "Content-Length: 3\r\n\r\n"), |
| 17624 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17625 | }; |
| 17626 | |
| 17627 | MockRead data_reads[] = { |
| 17628 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17629 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 17630 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 17631 | MockRead("Content-Length: 0\r\n\r\n"), |
| 17632 | MockRead(SYNCHRONOUS, OK), |
| 17633 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17634 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17635 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17636 | |
| 17637 | TestCompletionCallback callback; |
| 17638 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17639 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17640 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17641 | |
| 17642 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17643 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17644 | } |
| 17645 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17646 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17647 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17648 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17649 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17650 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17651 | |
| 17652 | HttpRequestInfo request; |
| 17653 | request.method = "POST"; |
| 17654 | request.url = GURL("http://www.foo.com/"); |
| 17655 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17656 | request.traffic_annotation = |
| 17657 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17658 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17659 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17660 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17661 | // Send headers successfully, but get an error while sending the body. |
| 17662 | MockWrite data_writes[] = { |
| 17663 | MockWrite("POST / HTTP/1.1\r\n" |
| 17664 | "Host: www.foo.com\r\n" |
| 17665 | "Connection: keep-alive\r\n" |
| 17666 | "Content-Length: 3\r\n\r\n"), |
| 17667 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17668 | }; |
| 17669 | |
| 17670 | MockRead data_reads[] = { |
| 17671 | MockRead("HTTP 0.9 rocks!"), |
| 17672 | MockRead(SYNCHRONOUS, OK), |
| 17673 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17674 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17675 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17676 | |
| 17677 | TestCompletionCallback callback; |
| 17678 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17679 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17680 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17681 | |
| 17682 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17683 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17684 | } |
| 17685 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17686 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17687 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17688 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17689 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17690 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17691 | |
| 17692 | HttpRequestInfo request; |
| 17693 | request.method = "POST"; |
| 17694 | request.url = GURL("http://www.foo.com/"); |
| 17695 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17696 | request.traffic_annotation = |
| 17697 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17698 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17699 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17700 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17701 | // Send headers successfully, but get an error while sending the body. |
| 17702 | MockWrite data_writes[] = { |
| 17703 | MockWrite("POST / HTTP/1.1\r\n" |
| 17704 | "Host: www.foo.com\r\n" |
| 17705 | "Connection: keep-alive\r\n" |
| 17706 | "Content-Length: 3\r\n\r\n"), |
| 17707 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17708 | }; |
| 17709 | |
| 17710 | MockRead data_reads[] = { |
| 17711 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 17712 | MockRead(SYNCHRONOUS, OK), |
| 17713 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17714 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17715 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17716 | |
| 17717 | TestCompletionCallback callback; |
| 17718 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17719 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17720 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17721 | |
| 17722 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17723 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17724 | } |
| 17725 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17726 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17727 | |
| 17728 | namespace { |
| 17729 | |
| 17730 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
| 17731 | headers->SetHeader("Connection", "Upgrade"); |
| 17732 | headers->SetHeader("Upgrade", "websocket"); |
| 17733 | headers->SetHeader("Origin", "http://www.example.org"); |
| 17734 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17735 | } |
| 17736 | |
| 17737 | } // namespace |
| 17738 | |
| 17739 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17740 | for (bool secure : {true, false}) { |
| 17741 | MockWrite data_writes[] = { |
| 17742 | MockWrite("GET / HTTP/1.1\r\n" |
| 17743 | "Host: www.example.org\r\n" |
| 17744 | "Connection: Upgrade\r\n" |
| 17745 | "Upgrade: websocket\r\n" |
| 17746 | "Origin: http://www.example.org\r\n" |
| 17747 | "Sec-WebSocket-Version: 13\r\n" |
| 17748 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17749 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17750 | "client_max_window_bits\r\n\r\n")}; |
| 17751 | |
| 17752 | MockRead data_reads[] = { |
| 17753 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17754 | "Upgrade: websocket\r\n" |
| 17755 | "Connection: Upgrade\r\n" |
| 17756 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
| 17757 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17758 | StaticSocketDataProvider data(data_reads, data_writes); |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17759 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17760 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17761 | if (secure) |
| 17762 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17763 | |
| 17764 | HttpRequestInfo request; |
| 17765 | request.method = "GET"; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17766 | request.url = |
| 17767 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 17768 | AddWebSocketHeaders(&request.extra_headers); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17769 | request.traffic_annotation = |
| 17770 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17771 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17772 | TestWebSocketHandshakeStreamCreateHelper |
| 17773 | websocket_handshake_stream_create_helper; |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17774 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17775 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17776 | HttpNetworkTransaction trans(LOW, session.get()); |
| 17777 | trans.SetWebSocketHandshakeStreamCreateHelper( |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17778 | &websocket_handshake_stream_create_helper); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17779 | |
| 17780 | TestCompletionCallback callback; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17781 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17782 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17783 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17784 | const HttpStreamRequest* stream_request = trans.stream_request_.get(); |
| 17785 | ASSERT_TRUE(stream_request); |
| 17786 | EXPECT_EQ(&websocket_handshake_stream_create_helper, |
| 17787 | stream_request->websocket_handshake_stream_create_helper()); |
| 17788 | |
| 17789 | rv = callback.WaitForResult(); |
| 17790 | EXPECT_THAT(rv, IsOk()); |
| 17791 | |
| 17792 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 17793 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17794 | } |
| 17795 | } |
| 17796 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17797 | // Verify that proxy headers are not sent to the destination server when |
| 17798 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17799 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17800 | HttpRequestInfo request; |
| 17801 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17802 | request.url = GURL("wss://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17803 | request.traffic_annotation = |
| 17804 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17805 | AddWebSocketHeaders(&request.extra_headers); |
| 17806 | |
| 17807 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17808 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17809 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17810 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17811 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17812 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17813 | |
| 17814 | // Since a proxy is configured, try to establish a tunnel. |
| 17815 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17816 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17817 | "Host: www.example.org:443\r\n" |
| 17818 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17819 | |
| 17820 | // After calling trans->RestartWithAuth(), this is the request we should |
| 17821 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17822 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17823 | "Host: www.example.org:443\r\n" |
| 17824 | "Proxy-Connection: keep-alive\r\n" |
| 17825 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17826 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17827 | MockWrite("GET / HTTP/1.1\r\n" |
| 17828 | "Host: www.example.org\r\n" |
| 17829 | "Connection: Upgrade\r\n" |
| 17830 | "Upgrade: websocket\r\n" |
| 17831 | "Origin: http://www.example.org\r\n" |
| 17832 | "Sec-WebSocket-Version: 13\r\n" |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17833 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17834 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17835 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17836 | |
| 17837 | // The proxy responds to the connect with a 407, using a persistent |
| 17838 | // connection. |
| 17839 | MockRead data_reads[] = { |
| 17840 | // No credentials. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17841 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 17842 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 17843 | "Content-Length: 0\r\n" |
| 17844 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17845 | |
| 17846 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17847 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17848 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17849 | "Upgrade: websocket\r\n" |
| 17850 | "Connection: Upgrade\r\n" |
| 17851 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17852 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17853 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17854 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17855 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17856 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17857 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17858 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17859 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17860 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17861 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17862 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17863 | &websocket_stream_create_helper); |
| 17864 | |
| 17865 | { |
| 17866 | TestCompletionCallback callback; |
| 17867 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17868 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17869 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17870 | |
| 17871 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17872 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17873 | } |
| 17874 | |
| 17875 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17876 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17877 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17878 | EXPECT_EQ(407, response->headers->response_code()); |
| 17879 | |
| 17880 | { |
| 17881 | TestCompletionCallback callback; |
| 17882 | |
| 17883 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 17884 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17885 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17886 | |
| 17887 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17888 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17889 | } |
| 17890 | |
| 17891 | response = trans->GetResponseInfo(); |
| 17892 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17893 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17894 | |
| 17895 | EXPECT_EQ(101, response->headers->response_code()); |
| 17896 | |
| 17897 | trans.reset(); |
| 17898 | session->CloseAllConnections(); |
| 17899 | } |
| 17900 | |
| 17901 | // Verify that proxy headers are not sent to the destination server when |
| 17902 | // establishing a tunnel for an insecure WebSocket connection. |
| 17903 | // This requires the authentication info to be injected into the auth cache |
| 17904 | // due to crbug.com/395064 |
| 17905 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17906 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17907 | HttpRequestInfo request; |
| 17908 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17909 | request.url = GURL("ws://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17910 | request.traffic_annotation = |
| 17911 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17912 | AddWebSocketHeaders(&request.extra_headers); |
| 17913 | |
| 17914 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17915 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17916 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17917 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17918 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17919 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17920 | |
| 17921 | MockWrite data_writes[] = { |
| 17922 | // Try to establish a tunnel for the WebSocket connection, with |
| 17923 | // credentials. Because WebSockets have a separate set of socket pools, |
| 17924 | // they cannot and will not use the same TCP/IP connection as the |
| 17925 | // preflight HTTP request. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17926 | MockWrite("CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 17927 | "Host: www.example.org:80\r\n" |
| 17928 | "Proxy-Connection: keep-alive\r\n" |
| 17929 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17930 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17931 | MockWrite("GET / HTTP/1.1\r\n" |
| 17932 | "Host: www.example.org\r\n" |
| 17933 | "Connection: Upgrade\r\n" |
| 17934 | "Upgrade: websocket\r\n" |
| 17935 | "Origin: http://www.example.org\r\n" |
| 17936 | "Sec-WebSocket-Version: 13\r\n" |
| 17937 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17938 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17939 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17940 | |
| 17941 | MockRead data_reads[] = { |
| 17942 | // HTTP CONNECT with credentials. |
| 17943 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17944 | |
| 17945 | // WebSocket connection established inside tunnel. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17946 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17947 | "Upgrade: websocket\r\n" |
| 17948 | "Connection: Upgrade\r\n" |
| 17949 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17950 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17951 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17952 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17953 | |
| 17954 | session->http_auth_cache()->Add( |
| 17955 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 17956 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 17957 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17958 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17959 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17960 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17961 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17962 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17963 | &websocket_stream_create_helper); |
| 17964 | |
| 17965 | TestCompletionCallback callback; |
| 17966 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17967 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17968 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17969 | |
| 17970 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17971 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17972 | |
| 17973 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17974 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17975 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17976 | |
| 17977 | EXPECT_EQ(101, response->headers->response_code()); |
| 17978 | |
| 17979 | trans.reset(); |
| 17980 | session->CloseAllConnections(); |
| 17981 | } |
| 17982 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17983 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17984 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17985 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17986 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17987 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17988 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17989 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17990 | |
| 17991 | HttpRequestInfo request; |
| 17992 | request.method = "POST"; |
| 17993 | request.url = GURL("http://www.foo.com/"); |
| 17994 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17995 | request.traffic_annotation = |
| 17996 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17997 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17998 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17999 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18000 | MockWrite data_writes[] = { |
| 18001 | MockWrite("POST / HTTP/1.1\r\n" |
| 18002 | "Host: www.foo.com\r\n" |
| 18003 | "Connection: keep-alive\r\n" |
| 18004 | "Content-Length: 3\r\n\r\n"), |
| 18005 | MockWrite("foo"), |
| 18006 | }; |
| 18007 | |
| 18008 | MockRead data_reads[] = { |
| 18009 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18010 | MockRead(SYNCHRONOUS, OK), |
| 18011 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18012 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18013 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18014 | |
| 18015 | TestCompletionCallback callback; |
| 18016 | |
| 18017 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18018 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18019 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18020 | |
| 18021 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18022 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18023 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18024 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18025 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18026 | } |
| 18027 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18028 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18029 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18030 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 18031 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 18032 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18033 | |
| 18034 | HttpRequestInfo request; |
| 18035 | request.method = "POST"; |
| 18036 | request.url = GURL("http://www.foo.com/"); |
| 18037 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18038 | request.traffic_annotation = |
| 18039 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18040 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18041 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18042 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18043 | MockWrite data_writes[] = { |
| 18044 | MockWrite("POST / HTTP/1.1\r\n" |
| 18045 | "Host: www.foo.com\r\n" |
| 18046 | "Connection: keep-alive\r\n" |
| 18047 | "Content-Length: 3\r\n\r\n"), |
| 18048 | MockWrite("foo"), |
| 18049 | }; |
| 18050 | |
| 18051 | MockRead data_reads[] = { |
| 18052 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 18053 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18054 | MockRead(SYNCHRONOUS, OK), |
| 18055 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18056 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18057 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18058 | |
| 18059 | TestCompletionCallback callback; |
| 18060 | |
| 18061 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18062 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18063 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18064 | |
| 18065 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18066 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18067 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18068 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18069 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18070 | } |
| 18071 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 18072 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18073 | ChunkedUploadDataStream upload_data_stream(0); |
| 18074 | |
| 18075 | HttpRequestInfo request; |
| 18076 | request.method = "POST"; |
| 18077 | request.url = GURL("http://www.foo.com/"); |
| 18078 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18079 | request.traffic_annotation = |
| 18080 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18081 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 18082 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18083 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18084 | // Send headers successfully, but get an error while sending the body. |
| 18085 | MockWrite data_writes[] = { |
| 18086 | MockWrite("POST / HTTP/1.1\r\n" |
| 18087 | "Host: www.foo.com\r\n" |
| 18088 | "Connection: keep-alive\r\n" |
| 18089 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 18090 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 18091 | }; |
| 18092 | |
| 18093 | MockRead data_reads[] = { |
| 18094 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 18095 | MockRead(SYNCHRONOUS, OK), |
| 18096 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18097 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18098 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18099 | |
| 18100 | TestCompletionCallback callback; |
| 18101 | |
| 18102 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 18103 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18104 | |
| 18105 | base::RunLoop().RunUntilIdle(); |
| 18106 | upload_data_stream.AppendData("f", 1, false); |
| 18107 | |
| 18108 | base::RunLoop().RunUntilIdle(); |
| 18109 | upload_data_stream.AppendData("oo", 2, true); |
| 18110 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 18111 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18112 | |
| 18113 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 18114 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18115 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18116 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 18117 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 18118 | } |
| 18119 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18120 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 18121 | const std::string& accept_encoding, |
| 18122 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18123 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18124 | bool should_match) { |
| 18125 | HttpRequestInfo request; |
| 18126 | request.method = "GET"; |
| 18127 | request.url = GURL("http://www.foo.com/"); |
| 18128 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 18129 | accept_encoding); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18130 | request.traffic_annotation = |
| 18131 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18132 | |
| 18133 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 18134 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18135 | // Send headers successfully, but get an error while sending the body. |
| 18136 | MockWrite data_writes[] = { |
| 18137 | MockWrite("GET / HTTP/1.1\r\n" |
| 18138 | "Host: www.foo.com\r\n" |
| 18139 | "Connection: keep-alive\r\n" |
| 18140 | "Accept-Encoding: "), |
| 18141 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 18142 | }; |
| 18143 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18144 | std::string response_code = "200 OK"; |
| 18145 | std::string extra; |
| 18146 | if (!location.empty()) { |
| 18147 | response_code = "301 Redirect\r\nLocation: "; |
| 18148 | response_code.append(location); |
| 18149 | } |
| 18150 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18151 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18152 | MockRead("HTTP/1.0 "), |
| 18153 | MockRead(response_code.data()), |
| 18154 | MockRead("\r\nContent-Encoding: "), |
| 18155 | MockRead(content_encoding.data()), |
| 18156 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18157 | MockRead(SYNCHRONOUS, OK), |
| 18158 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18159 | StaticSocketDataProvider data(data_reads, data_writes); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18160 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 18161 | |
| 18162 | TestCompletionCallback callback; |
| 18163 | |
| 18164 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18165 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18166 | |
| 18167 | rv = callback.WaitForResult(); |
| 18168 | if (should_match) { |
| 18169 | EXPECT_THAT(rv, IsOk()); |
| 18170 | } else { |
| 18171 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 18172 | } |
| 18173 | } |
| 18174 | |
| 18175 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18176 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18177 | } |
| 18178 | |
| 18179 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18180 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 18181 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18182 | } |
| 18183 | |
| 18184 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 18185 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18186 | "", false); |
| 18187 | } |
| 18188 | |
| 18189 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 18190 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 18191 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18192 | } |
| 18193 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18194 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 18195 | ProxyConfig proxy_config; |
| 18196 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18197 | proxy_config.set_pac_mandatory(true); |
| 18198 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18199 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18200 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18201 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 18202 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18203 | |
| 18204 | HttpRequestInfo request; |
| 18205 | request.method = "GET"; |
| 18206 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18207 | request.traffic_annotation = |
| 18208 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18209 | |
| 18210 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18211 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18212 | |
| 18213 | TestCompletionCallback callback; |
| 18214 | |
| 18215 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18216 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18217 | EXPECT_THAT(callback.WaitForResult(), |
| 18218 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18219 | } |
| 18220 | |
| 18221 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 18222 | ProxyConfig proxy_config; |
| 18223 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18224 | proxy_config.set_pac_mandatory(true); |
| 18225 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 18226 | new MockAsyncProxyResolverFactory(false); |
| 18227 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18228 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18229 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18230 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18231 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18232 | HttpRequestInfo request; |
| 18233 | request.method = "GET"; |
| 18234 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18235 | request.traffic_annotation = |
| 18236 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18237 | |
| 18238 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18239 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18240 | |
| 18241 | TestCompletionCallback callback; |
| 18242 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18243 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18244 | |
| 18245 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 18246 | ERR_FAILED, &resolver); |
| 18247 | EXPECT_THAT(callback.WaitForResult(), |
| 18248 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18249 | } |
| 18250 | |
| 18251 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18252 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18253 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18254 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18255 | session_deps_.enable_quic = false; |
| 18256 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18257 | |
| 18258 | HttpRequestInfo request; |
| 18259 | request.method = "GET"; |
| 18260 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18261 | request.traffic_annotation = |
| 18262 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18263 | |
| 18264 | TestCompletionCallback callback; |
| 18265 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18266 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18267 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18268 | |
| 18269 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 18270 | } |
| 18271 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18272 | //----------------------------------------------------------------------------- |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18273 | // Reporting tests |
| 18274 | |
| 18275 | #if BUILDFLAG(ENABLE_REPORTING) |
| 18276 | class HttpNetworkTransactionReportingTest : public HttpNetworkTransactionTest { |
| 18277 | protected: |
| 18278 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18279 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18280 | auto test_reporting_context = std::make_unique<TestReportingContext>( |
| 18281 | &clock_, &tick_clock_, ReportingPolicy()); |
| 18282 | test_reporting_context_ = test_reporting_context.get(); |
| 18283 | session_deps_.reporting_service = |
| 18284 | ReportingService::CreateForTesting(std::move(test_reporting_context)); |
| 18285 | } |
| 18286 | |
| 18287 | TestReportingContext* reporting_context() const { |
| 18288 | return test_reporting_context_; |
| 18289 | } |
| 18290 | |
| 18291 | void clear_reporting_service() { |
| 18292 | session_deps_.reporting_service.reset(); |
| 18293 | test_reporting_context_ = nullptr; |
| 18294 | } |
| 18295 | |
| 18296 | // Makes an HTTPS request that should install a valid Reporting policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18297 | void RequestPolicy(CertStatus cert_status = 0) { |
| 18298 | HttpRequestInfo request; |
| 18299 | request.method = "GET"; |
| 18300 | request.url = GURL(url_); |
| 18301 | request.traffic_annotation = |
| 18302 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18303 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18304 | MockWrite data_writes[] = { |
| 18305 | MockWrite("GET / HTTP/1.1\r\n" |
| 18306 | "Host: www.example.org\r\n" |
| 18307 | "Connection: keep-alive\r\n\r\n"), |
| 18308 | }; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18309 | MockRead data_reads[] = { |
| 18310 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18311 | MockRead("Report-To: {\"group\": \"nel\", \"max_age\": 86400, " |
| 18312 | "\"endpoints\": [{\"url\": " |
| 18313 | "\"https://www.example.org/upload/\"}]}\r\n"), |
| 18314 | MockRead("\r\n"), |
| 18315 | MockRead("hello world"), |
| 18316 | MockRead(SYNCHRONOUS, OK), |
| 18317 | }; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18318 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18319 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18320 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18321 | |
| 18322 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18323 | if (request.url.SchemeIsCryptographic()) { |
| 18324 | ssl.ssl_info.cert = |
| 18325 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18326 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18327 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18328 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18329 | } |
| 18330 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18331 | TestCompletionCallback callback; |
| 18332 | auto session = CreateSession(&session_deps_); |
| 18333 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18334 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18335 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18336 | } |
| 18337 | |
| 18338 | protected: |
| 18339 | std::string url_ = "https://www.example.org/"; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18340 | |
| 18341 | private: |
| 18342 | TestReportingContext* test_reporting_context_; |
| 18343 | }; |
| 18344 | |
| 18345 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18346 | DontProcessReportToHeaderNoService) { |
| 18347 | base::HistogramTester histograms; |
| 18348 | clear_reporting_service(); |
| 18349 | RequestPolicy(); |
| 18350 | histograms.ExpectBucketCount( |
| 18351 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18352 | ReportingHeaderParser::HeaderOutcome::DISCARDED_NO_REPORTING_SERVICE, 1); |
| 18353 | } |
| 18354 | |
| 18355 | TEST_F(HttpNetworkTransactionReportingTest, DontProcessReportToHeaderHttp) { |
| 18356 | base::HistogramTester histograms; |
| 18357 | url_ = "http://www.example.org/"; |
| 18358 | RequestPolicy(); |
| 18359 | histograms.ExpectBucketCount( |
| 18360 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18361 | ReportingHeaderParser::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18362 | } |
| 18363 | |
| 18364 | TEST_F(HttpNetworkTransactionReportingTest, ProcessReportToHeaderHttps) { |
| 18365 | RequestPolicy(); |
| 18366 | std::vector<const ReportingClient*> clients; |
| 18367 | reporting_context()->cache()->GetClients(&clients); |
| 18368 | ASSERT_EQ(1u, clients.size()); |
| 18369 | const auto* client = clients[0]; |
| 18370 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 18371 | client->origin); |
| 18372 | EXPECT_EQ(GURL("https://www.example.org/upload/"), client->endpoint); |
| 18373 | EXPECT_EQ("nel", client->group); |
| 18374 | } |
| 18375 | |
| 18376 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18377 | DontProcessReportToHeaderInvalidHttps) { |
| 18378 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18379 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18380 | RequestPolicy(cert_status); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18381 | histograms.ExpectBucketCount( |
| 18382 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18383 | ReportingHeaderParser::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, 1); |
| 18384 | } |
| 18385 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 18386 | |
| 18387 | //----------------------------------------------------------------------------- |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18388 | // Network Error Logging tests |
| 18389 | |
| 18390 | #if BUILDFLAG(ENABLE_REPORTING) |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18391 | namespace { |
| 18392 | |
| 18393 | const char kUserAgent[] = "Mozilla/1.0"; |
| 18394 | const char kReferrer[] = "https://www.referrer.org/"; |
| 18395 | |
| 18396 | } // namespace |
| 18397 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18398 | class HttpNetworkTransactionNetworkErrorLoggingTest |
| 18399 | : public HttpNetworkTransactionTest { |
| 18400 | protected: |
| 18401 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18402 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18403 | auto network_error_logging_service = |
| 18404 | std::make_unique<TestNetworkErrorLoggingService>(); |
| 18405 | test_network_error_logging_service_ = network_error_logging_service.get(); |
| 18406 | session_deps_.network_error_logging_service = |
| 18407 | std::move(network_error_logging_service); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18408 | |
| 18409 | extra_headers_.SetHeader("User-Agent", kUserAgent); |
| 18410 | extra_headers_.SetHeader("Referer", kReferrer); |
| 18411 | |
| 18412 | request_.method = "GET"; |
| 18413 | request_.url = GURL(url_); |
| 18414 | request_.extra_headers = extra_headers_; |
| 18415 | request_.reporting_upload_depth = reporting_upload_depth_; |
| 18416 | request_.traffic_annotation = |
| 18417 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18418 | } |
| 18419 | |
| 18420 | TestNetworkErrorLoggingService* network_error_logging_service() const { |
| 18421 | return test_network_error_logging_service_; |
| 18422 | } |
| 18423 | |
| 18424 | void clear_network_error_logging_service() { |
| 18425 | session_deps_.network_error_logging_service.reset(); |
| 18426 | test_network_error_logging_service_ = nullptr; |
| 18427 | } |
| 18428 | |
| 18429 | // Makes an HTTPS request that should install a valid NEL policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18430 | void RequestPolicy(CertStatus cert_status = 0) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18431 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18432 | MockWrite data_writes[] = { |
| 18433 | MockWrite("GET / HTTP/1.1\r\n" |
| 18434 | "Host: www.example.org\r\n" |
| 18435 | "Connection: keep-alive\r\n"), |
| 18436 | MockWrite(ASYNC, extra_header_string.data(), |
| 18437 | extra_header_string.size()), |
| 18438 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18439 | MockRead data_reads[] = { |
| 18440 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18441 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18442 | MockRead("\r\n"), |
| 18443 | MockRead("hello world"), |
| 18444 | MockRead(SYNCHRONOUS, OK), |
| 18445 | }; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18446 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18447 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18448 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18449 | |
| 18450 | SSLSocketDataProvider ssl(ASYNC, OK); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18451 | if (request_.url.SchemeIsCryptographic()) { |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18452 | ssl.ssl_info.cert = |
| 18453 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18454 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18455 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18456 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18457 | } |
| 18458 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18459 | TestCompletionCallback callback; |
| 18460 | auto session = CreateSession(&session_deps_); |
| 18461 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18462 | int rv = trans.Start(&request_, callback.callback(), NetLogWithSource()); |
| 18463 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18464 | |
| 18465 | std::string response_data; |
| 18466 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 18467 | EXPECT_EQ("hello world", response_data); |
| 18468 | } |
| 18469 | |
| 18470 | void CheckReport(size_t index, |
| 18471 | int status_code, |
| 18472 | int error_type, |
| 18473 | IPAddress server_ip = IPAddress::IPv4Localhost()) { |
| 18474 | ASSERT_LT(index, network_error_logging_service()->errors().size()); |
| 18475 | |
| 18476 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18477 | network_error_logging_service()->errors()[index]; |
| 18478 | EXPECT_EQ(url_, error.uri); |
| 18479 | EXPECT_EQ(kReferrer, error.referrer); |
| 18480 | EXPECT_EQ(kUserAgent, error.user_agent); |
| 18481 | EXPECT_EQ(server_ip, error.server_ip); |
| 18482 | EXPECT_EQ("http/1.1", error.protocol); |
| 18483 | EXPECT_EQ("GET", error.method); |
| 18484 | EXPECT_EQ(status_code, error.status_code); |
| 18485 | EXPECT_EQ(error_type, error.type); |
| 18486 | EXPECT_EQ(0, error.reporting_upload_depth); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18487 | } |
| 18488 | |
| 18489 | protected: |
| 18490 | std::string url_ = "https://www.example.org/"; |
| 18491 | CertStatus cert_status_ = 0; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18492 | HttpRequestInfo request_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18493 | HttpRequestHeaders extra_headers_; |
| 18494 | int reporting_upload_depth_ = 0; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18495 | |
| 18496 | private: |
| 18497 | TestNetworkErrorLoggingService* test_network_error_logging_service_; |
| 18498 | }; |
| 18499 | |
| 18500 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18501 | DontProcessNelHeaderNoService) { |
| 18502 | base::HistogramTester histograms; |
| 18503 | clear_network_error_logging_service(); |
| 18504 | RequestPolicy(); |
| 18505 | histograms.ExpectBucketCount( |
| 18506 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18507 | NetworkErrorLoggingService::HeaderOutcome:: |
| 18508 | DISCARDED_NO_NETWORK_ERROR_LOGGING_SERVICE, |
| 18509 | 1); |
| 18510 | } |
| 18511 | |
| 18512 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18513 | DontProcessNelHeaderHttp) { |
| 18514 | base::HistogramTester histograms; |
| 18515 | url_ = "http://www.example.org/"; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18516 | request_.url = GURL(url_); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18517 | RequestPolicy(); |
| 18518 | histograms.ExpectBucketCount( |
| 18519 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18520 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18521 | } |
| 18522 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 18523 | // Don't set NEL policies received on a proxied connection. |
| 18524 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18525 | DontProcessNelHeaderProxy) { |
| 18526 | session_deps_.proxy_resolution_service = |
| 18527 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18528 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18529 | BoundTestNetLog log; |
| 18530 | session_deps_.net_log = log.bound().net_log(); |
| 18531 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18532 | |
| 18533 | HttpRequestInfo request; |
| 18534 | request.method = "GET"; |
| 18535 | request.url = GURL("https://www.example.org/"); |
| 18536 | request.traffic_annotation = |
| 18537 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18538 | |
| 18539 | // Since we have proxy, should try to establish tunnel. |
| 18540 | MockWrite data_writes1[] = { |
| 18541 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 18542 | "Host: www.example.org:443\r\n" |
| 18543 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 18544 | |
| 18545 | MockWrite("GET / HTTP/1.1\r\n" |
| 18546 | "Host: www.example.org\r\n" |
| 18547 | "Connection: keep-alive\r\n\r\n"), |
| 18548 | }; |
| 18549 | |
| 18550 | MockRead data_reads1[] = { |
| 18551 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 18552 | |
| 18553 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 18554 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18555 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18556 | MockRead("Content-Length: 100\r\n\r\n"), |
| 18557 | MockRead(SYNCHRONOUS, OK), |
| 18558 | }; |
| 18559 | |
| 18560 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18561 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18562 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18563 | ssl.ssl_info.cert = |
| 18564 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18565 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 18566 | ssl.ssl_info.cert_status = 0; |
| 18567 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18568 | |
| 18569 | TestCompletionCallback callback1; |
| 18570 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18571 | |
| 18572 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
| 18573 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18574 | |
| 18575 | rv = callback1.WaitForResult(); |
| 18576 | EXPECT_THAT(rv, IsOk()); |
| 18577 | |
| 18578 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 18579 | ASSERT_TRUE(response); |
| 18580 | EXPECT_EQ(200, response->headers->response_code()); |
| 18581 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 18582 | |
| 18583 | // No NEL header was set. |
| 18584 | EXPECT_EQ(0u, network_error_logging_service()->headers().size()); |
| 18585 | } |
| 18586 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18587 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ProcessNelHeaderHttps) { |
| 18588 | RequestPolicy(); |
| 18589 | ASSERT_EQ(1u, network_error_logging_service()->headers().size()); |
| 18590 | const auto& header = network_error_logging_service()->headers()[0]; |
| 18591 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 18592 | header.origin); |
| 18593 | EXPECT_EQ(IPAddress::IPv4Localhost(), header.received_ip_address); |
| 18594 | EXPECT_EQ("{\"report_to\": \"nel\", \"max_age\": 86400}", header.value); |
| 18595 | } |
| 18596 | |
| 18597 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18598 | DontProcessNelHeaderInvalidHttps) { |
| 18599 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18600 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18601 | RequestPolicy(cert_status); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18602 | histograms.ExpectBucketCount( |
| 18603 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18604 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, |
| 18605 | 1); |
| 18606 | } |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18607 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18608 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, CreateReportSuccess) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18609 | RequestPolicy(); |
| 18610 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18611 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 18612 | } |
| 18613 | |
| 18614 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18615 | CreateReportErrorAfterStart) { |
| 18616 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18617 | auto trans = |
| 18618 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18619 | |
| 18620 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
| 18621 | StaticSocketDataProvider data; |
| 18622 | data.set_connect_data(mock_connect); |
| 18623 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18624 | |
| 18625 | TestCompletionCallback callback; |
| 18626 | |
| 18627 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18628 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18629 | |
| 18630 | trans.reset(); |
| 18631 | |
| 18632 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18633 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18634 | IPAddress() /* server_ip */); |
| 18635 | } |
| 18636 | |
| 18637 | // Same as above except the error is ASYNC |
| 18638 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18639 | CreateReportErrorAfterStartAsync) { |
| 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(ASYNC, 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 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18662 | CreateReportReadBodyError) { |
| 18663 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18664 | MockWrite data_writes[] = { |
| 18665 | MockWrite("GET / HTTP/1.1\r\n" |
| 18666 | "Host: www.example.org\r\n" |
| 18667 | "Connection: keep-alive\r\n"), |
| 18668 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18669 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18670 | MockRead data_reads[] = { |
| 18671 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18672 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18673 | MockRead("hello world"), |
| 18674 | MockRead(SYNCHRONOUS, OK), |
| 18675 | }; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18676 | |
| 18677 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18678 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18679 | |
| 18680 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18681 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18682 | |
| 18683 | // Log start time |
| 18684 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18685 | |
| 18686 | TestCompletionCallback callback; |
| 18687 | auto session = CreateSession(&session_deps_); |
| 18688 | auto trans = |
| 18689 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18690 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18691 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18692 | |
| 18693 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18694 | ASSERT_TRUE(response); |
| 18695 | |
| 18696 | EXPECT_TRUE(response->headers); |
| 18697 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 18698 | |
| 18699 | std::string response_data; |
| 18700 | rv = ReadTransaction(trans.get(), &response_data); |
| 18701 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 18702 | |
| 18703 | trans.reset(); |
| 18704 | |
| 18705 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18706 | |
| 18707 | CheckReport(0 /* index */, 200 /* status_code */, |
| 18708 | ERR_CONTENT_LENGTH_MISMATCH); |
| 18709 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18710 | network_error_logging_service()->errors()[0]; |
| 18711 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 18712 | } |
| 18713 | |
| 18714 | // Same as above except the final read is ASYNC. |
| 18715 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18716 | CreateReportReadBodyErrorAsync) { |
| 18717 | std::string extra_header_string = extra_headers_.ToString(); |
Lily Chen | 29c0403 | 2019-02-25 21:50:53 | [diff] [blame] | 18718 | MockWrite data_writes[] = { |
| 18719 | MockWrite("GET / HTTP/1.1\r\n" |
| 18720 | "Host: www.example.org\r\n" |
| 18721 | "Connection: keep-alive\r\n"), |
| 18722 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18723 | }; |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 18724 | MockRead data_reads[] = { |
| 18725 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18726 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18727 | MockRead("hello world"), |
| 18728 | MockRead(ASYNC, OK), |
| 18729 | }; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18730 | |
| 18731 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18732 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18733 | |
| 18734 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18735 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18736 | |
| 18737 | // Log start time |
| 18738 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18739 | |
| 18740 | TestCompletionCallback callback; |
| 18741 | auto session = CreateSession(&session_deps_); |
| 18742 | auto trans = |
| 18743 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18744 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18745 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18746 | |
| 18747 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18748 | ASSERT_TRUE(response); |
| 18749 | |
| 18750 | EXPECT_TRUE(response->headers); |
| 18751 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 18752 | |
| 18753 | std::string response_data; |
| 18754 | rv = ReadTransaction(trans.get(), &response_data); |
| 18755 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 18756 | |
| 18757 | trans.reset(); |
| 18758 | |
| 18759 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18760 | |
| 18761 | CheckReport(0 /* index */, 200 /* status_code */, |
| 18762 | ERR_CONTENT_LENGTH_MISMATCH); |
| 18763 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18764 | network_error_logging_service()->errors()[0]; |
| 18765 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 18766 | } |
| 18767 | |
| 18768 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18769 | CreateReportRestartWithAuth) { |
| 18770 | std::string extra_header_string = extra_headers_.ToString(); |
| 18771 | static const base::TimeDelta kSleepDuration = |
| 18772 | base::TimeDelta::FromMilliseconds(10); |
| 18773 | |
| 18774 | MockWrite data_writes1[] = { |
| 18775 | MockWrite("GET / HTTP/1.1\r\n" |
| 18776 | "Host: www.example.org\r\n" |
| 18777 | "Connection: keep-alive\r\n"), |
| 18778 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18779 | }; |
| 18780 | |
| 18781 | MockRead data_reads1[] = { |
| 18782 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 18783 | // Give a couple authenticate options (only the middle one is actually |
| 18784 | // supported). |
| 18785 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 18786 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 18787 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 18788 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18789 | // Large content-length -- won't matter, as connection will be reset. |
| 18790 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 18791 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 18792 | }; |
| 18793 | |
| 18794 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18795 | // be issuing -- the final header line contains the credentials. |
| 18796 | MockWrite data_writes2[] = { |
| 18797 | MockWrite("GET / HTTP/1.1\r\n" |
| 18798 | "Host: www.example.org\r\n" |
| 18799 | "Connection: keep-alive\r\n" |
| 18800 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 18801 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18802 | }; |
| 18803 | |
| 18804 | // Lastly, the server responds with the actual content. |
| 18805 | MockRead data_reads2[] = { |
| 18806 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 18807 | MockRead("hello world"), |
| 18808 | MockRead(SYNCHRONOUS, OK), |
| 18809 | }; |
| 18810 | |
| 18811 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18812 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 18813 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18814 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18815 | |
| 18816 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18817 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18818 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18819 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18820 | |
| 18821 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18822 | base::TimeTicks restart_time; |
| 18823 | |
| 18824 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18825 | auto trans = |
| 18826 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18827 | |
| 18828 | TestCompletionCallback callback1; |
| 18829 | |
| 18830 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18831 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18832 | |
| 18833 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18834 | |
| 18835 | TestCompletionCallback callback2; |
| 18836 | |
| 18837 | // Wait 10 ms then restart with auth |
| 18838 | FastForwardBy(kSleepDuration); |
| 18839 | restart_time = base::TimeTicks::Now(); |
| 18840 | rv = |
| 18841 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 18842 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18843 | |
| 18844 | std::string response_data; |
| 18845 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 18846 | EXPECT_EQ("hello world", response_data); |
| 18847 | |
| 18848 | trans.reset(); |
| 18849 | |
| 18850 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 18851 | // retry. Note that we don't report the error draining the body, as the first |
| 18852 | // request already generated a report for the auth challenge. |
| 18853 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 18854 | |
| 18855 | // Check error report contents |
| 18856 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 18857 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 18858 | |
| 18859 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 18860 | network_error_logging_service()->errors()[0]; |
| 18861 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 18862 | network_error_logging_service()->errors()[1]; |
| 18863 | |
| 18864 | // Sanity-check elapsed time values |
| 18865 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 18866 | // Check that the start time is refreshed when restarting with auth. |
| 18867 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 18868 | } |
| 18869 | |
| 18870 | // Same as above, except draining the body before restarting fails |
| 18871 | // asynchronously. |
| 18872 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18873 | CreateReportRestartWithAuthAsync) { |
| 18874 | std::string extra_header_string = extra_headers_.ToString(); |
| 18875 | static const base::TimeDelta kSleepDuration = |
| 18876 | base::TimeDelta::FromMilliseconds(10); |
| 18877 | |
| 18878 | MockWrite data_writes1[] = { |
| 18879 | MockWrite("GET / HTTP/1.1\r\n" |
| 18880 | "Host: www.example.org\r\n" |
| 18881 | "Connection: keep-alive\r\n"), |
| 18882 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18883 | }; |
| 18884 | |
| 18885 | MockRead data_reads1[] = { |
| 18886 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 18887 | // Give a couple authenticate options (only the middle one is actually |
| 18888 | // supported). |
| 18889 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 18890 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 18891 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 18892 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18893 | // Large content-length -- won't matter, as connection will be reset. |
| 18894 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 18895 | MockRead(ASYNC, ERR_FAILED), |
| 18896 | }; |
| 18897 | |
| 18898 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18899 | // be issuing -- the final header line contains the credentials. |
| 18900 | MockWrite data_writes2[] = { |
| 18901 | MockWrite("GET / HTTP/1.1\r\n" |
| 18902 | "Host: www.example.org\r\n" |
| 18903 | "Connection: keep-alive\r\n" |
| 18904 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 18905 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18906 | }; |
| 18907 | |
| 18908 | // Lastly, the server responds with the actual content. |
| 18909 | MockRead data_reads2[] = { |
| 18910 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 18911 | MockRead("hello world"), |
| 18912 | MockRead(SYNCHRONOUS, OK), |
| 18913 | }; |
| 18914 | |
| 18915 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18916 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 18917 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18918 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18919 | |
| 18920 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18921 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18922 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18923 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18924 | |
| 18925 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18926 | base::TimeTicks restart_time; |
| 18927 | |
| 18928 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18929 | auto trans = |
| 18930 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18931 | |
| 18932 | TestCompletionCallback callback1; |
| 18933 | |
| 18934 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18935 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18936 | |
| 18937 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18938 | |
| 18939 | TestCompletionCallback callback2; |
| 18940 | |
| 18941 | // Wait 10 ms then restart with auth |
| 18942 | FastForwardBy(kSleepDuration); |
| 18943 | restart_time = base::TimeTicks::Now(); |
| 18944 | rv = |
| 18945 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 18946 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18947 | |
| 18948 | std::string response_data; |
| 18949 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 18950 | EXPECT_EQ("hello world", response_data); |
| 18951 | |
| 18952 | trans.reset(); |
| 18953 | |
| 18954 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 18955 | // retry. Note that we don't report the error draining the body, as the first |
| 18956 | // request already generated a report for the auth challenge. |
| 18957 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 18958 | |
| 18959 | // Check error report contents |
| 18960 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 18961 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 18962 | |
| 18963 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 18964 | network_error_logging_service()->errors()[0]; |
| 18965 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 18966 | network_error_logging_service()->errors()[1]; |
| 18967 | |
| 18968 | // Sanity-check elapsed time values |
| 18969 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 18970 | // Check that the start time is refreshed when restarting with auth. |
| 18971 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 18972 | } |
| 18973 | |
| 18974 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18975 | CreateReportRetryKeepAliveConnectionReset) { |
| 18976 | std::string extra_header_string = extra_headers_.ToString(); |
| 18977 | MockWrite data_writes1[] = { |
| 18978 | MockWrite("GET / HTTP/1.1\r\n" |
| 18979 | "Host: www.example.org\r\n" |
| 18980 | "Connection: keep-alive\r\n"), |
| 18981 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18982 | MockWrite("GET / HTTP/1.1\r\n" |
| 18983 | "Host: www.example.org\r\n" |
| 18984 | "Connection: keep-alive\r\n"), |
| 18985 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18986 | }; |
| 18987 | |
| 18988 | MockRead data_reads1[] = { |
| 18989 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 18990 | MockRead("hello"), |
| 18991 | // Connection is reset |
| 18992 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 18993 | }; |
| 18994 | |
| 18995 | // Successful retry |
| 18996 | MockRead data_reads2[] = { |
| 18997 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 18998 | MockRead("world"), |
| 18999 | MockRead(ASYNC, OK), |
| 19000 | }; |
| 19001 | |
| 19002 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19003 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 19004 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19005 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19006 | |
| 19007 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 19008 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 19009 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 19010 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 19011 | |
| 19012 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19013 | auto trans1 = |
| 19014 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19015 | |
| 19016 | TestCompletionCallback callback1; |
| 19017 | |
| 19018 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 19019 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19020 | |
| 19021 | std::string response_data; |
| 19022 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19023 | EXPECT_EQ("hello", response_data); |
| 19024 | |
| 19025 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19026 | |
| 19027 | auto trans2 = |
| 19028 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19029 | |
| 19030 | TestCompletionCallback callback2; |
| 19031 | |
| 19032 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 19033 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19034 | |
| 19035 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19036 | EXPECT_EQ("world", response_data); |
| 19037 | |
| 19038 | trans1.reset(); |
| 19039 | trans2.reset(); |
| 19040 | |
| 19041 | // One OK report from first request, then a ERR_CONNECTION_RESET report from |
| 19042 | // the second request, then an OK report from the successful retry. |
| 19043 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19044 | |
| 19045 | // Check error report contents |
| 19046 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19047 | CheckReport(1 /* index */, 0 /* status_code */, ERR_CONNECTION_RESET); |
| 19048 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 19049 | } |
| 19050 | |
| 19051 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19052 | CreateReportRetryKeepAlive408) { |
| 19053 | std::string extra_header_string = extra_headers_.ToString(); |
| 19054 | MockWrite data_writes1[] = { |
| 19055 | MockWrite("GET / HTTP/1.1\r\n" |
| 19056 | "Host: www.example.org\r\n" |
| 19057 | "Connection: keep-alive\r\n"), |
| 19058 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19059 | MockWrite("GET / HTTP/1.1\r\n" |
| 19060 | "Host: www.example.org\r\n" |
| 19061 | "Connection: keep-alive\r\n"), |
| 19062 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19063 | }; |
| 19064 | |
| 19065 | MockRead data_reads1[] = { |
| 19066 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19067 | MockRead("hello"), |
| 19068 | // 408 Request Timeout |
| 19069 | MockRead(SYNCHRONOUS, |
| 19070 | "HTTP/1.1 408 Request Timeout\r\n" |
| 19071 | "Connection: Keep-Alive\r\n" |
| 19072 | "Content-Length: 6\r\n\r\n" |
| 19073 | "Pickle"), |
| 19074 | }; |
| 19075 | |
| 19076 | // Successful retry |
| 19077 | MockRead data_reads2[] = { |
| 19078 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 19079 | MockRead("world"), |
| 19080 | MockRead(ASYNC, OK), |
| 19081 | }; |
| 19082 | |
| 19083 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19084 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 19085 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19086 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19087 | |
| 19088 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 19089 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 19090 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 19091 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 19092 | |
| 19093 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19094 | auto trans1 = |
| 19095 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19096 | |
| 19097 | TestCompletionCallback callback1; |
| 19098 | |
| 19099 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 19100 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19101 | |
| 19102 | std::string response_data; |
| 19103 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19104 | EXPECT_EQ("hello", response_data); |
| 19105 | |
| 19106 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19107 | |
| 19108 | auto trans2 = |
| 19109 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19110 | |
| 19111 | TestCompletionCallback callback2; |
| 19112 | |
| 19113 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 19114 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19115 | |
| 19116 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19117 | EXPECT_EQ("world", response_data); |
| 19118 | |
| 19119 | trans1.reset(); |
| 19120 | trans2.reset(); |
| 19121 | |
| 19122 | // One 200 report from first request, then a 408 report from |
| 19123 | // the second request, then a 200 report from the successful retry. |
| 19124 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19125 | |
| 19126 | // Check error report contents |
| 19127 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19128 | CheckReport(1 /* index */, 408 /* status_code */, OK); |
| 19129 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 19130 | } |
| 19131 | |
| 19132 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19133 | CreateReportRetry421WithoutConnectionPooling) { |
| 19134 | // Two hosts resolve to the same IP address. |
| 19135 | const std::string ip_addr = "1.2.3.4"; |
| 19136 | IPAddress ip; |
| 19137 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 19138 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 19139 | |
| 19140 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
| 19141 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 19142 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 19143 | |
| 19144 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19145 | |
| 19146 | // Two requests on the first connection. |
| 19147 | spdy::SpdySerializedFrame req1( |
| 19148 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 19149 | spdy_util_.UpdateWithStreamDestruction(1); |
| 19150 | spdy::SpdySerializedFrame req2( |
| 19151 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 19152 | spdy::SpdySerializedFrame rst( |
| 19153 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
| 19154 | MockWrite writes1[] = { |
| 19155 | CreateMockWrite(req1, 0), |
| 19156 | CreateMockWrite(req2, 3), |
| 19157 | CreateMockWrite(rst, 6), |
| 19158 | }; |
| 19159 | |
| 19160 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 19161 | spdy::SpdySerializedFrame resp1( |
| 19162 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 19163 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 19164 | spdy::SpdyHeaderBlock response_headers; |
| 19165 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 19166 | spdy::SpdySerializedFrame resp2( |
| 19167 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 19168 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 19169 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 19170 | |
| 19171 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 19172 | SequencedSocketData data1(connect1, reads1, writes1); |
| 19173 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19174 | |
| 19175 | AddSSLSocketData(); |
| 19176 | |
| 19177 | // Retry the second request on a second connection. |
| 19178 | SpdyTestUtil spdy_util2; |
| 19179 | spdy::SpdySerializedFrame req3( |
| 19180 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 19181 | MockWrite writes2[] = { |
| 19182 | CreateMockWrite(req3, 0), |
| 19183 | }; |
| 19184 | |
| 19185 | spdy::SpdySerializedFrame resp3( |
| 19186 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 19187 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 19188 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 19189 | MockRead(ASYNC, 0, 3)}; |
| 19190 | |
| 19191 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 19192 | SequencedSocketData data2(connect2, reads2, writes2); |
| 19193 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19194 | |
| 19195 | AddSSLSocketData(); |
| 19196 | |
| 19197 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 19198 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 19199 | HostPortPair("mail.example.com", 443), base::nullopt); |
| 19200 | EXPECT_THAT(rv, IsOk()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19201 | |
| 19202 | HttpRequestInfo request1; |
| 19203 | request1.method = "GET"; |
| 19204 | request1.url = GURL("https://www.example.org/"); |
| 19205 | request1.load_flags = 0; |
| 19206 | request1.traffic_annotation = |
| 19207 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19208 | auto trans1 = |
| 19209 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19210 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 19211 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19212 | rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 19213 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19214 | |
| 19215 | const HttpResponseInfo* response = trans1->GetResponseInfo(); |
| 19216 | ASSERT_TRUE(response); |
| 19217 | ASSERT_TRUE(response->headers); |
| 19218 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19219 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19220 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19221 | std::string response_data; |
| 19222 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19223 | EXPECT_EQ("hello!", response_data); |
| 19224 | |
| 19225 | trans1.reset(); |
| 19226 | |
| 19227 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19228 | |
| 19229 | HttpRequestInfo request2; |
| 19230 | request2.method = "GET"; |
| 19231 | request2.url = GURL("https://mail.example.org/"); |
| 19232 | request2.load_flags = 0; |
| 19233 | request2.traffic_annotation = |
| 19234 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19235 | auto trans2 = |
| 19236 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19237 | |
| 19238 | BoundTestNetLog log; |
| 19239 | rv = trans2->Start(&request2, callback.callback(), log.bound()); |
| 19240 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19241 | |
| 19242 | response = trans2->GetResponseInfo(); |
| 19243 | ASSERT_TRUE(response); |
| 19244 | ASSERT_TRUE(response->headers); |
| 19245 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19246 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19247 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19248 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19249 | EXPECT_EQ("hello!", response_data); |
| 19250 | |
| 19251 | trans2.reset(); |
| 19252 | |
| 19253 | // One 200 report from the first request, then a 421 report from the |
| 19254 | // second request, then a 200 report from the successful retry. |
| 19255 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19256 | |
| 19257 | // Check error report contents |
| 19258 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 19259 | network_error_logging_service()->errors()[0]; |
| 19260 | EXPECT_EQ(GURL("https://www.example.org/"), error1.uri); |
| 19261 | EXPECT_TRUE(error1.referrer.is_empty()); |
| 19262 | EXPECT_EQ("", error1.user_agent); |
| 19263 | EXPECT_EQ(ip, error1.server_ip); |
| 19264 | EXPECT_EQ("h2", error1.protocol); |
| 19265 | EXPECT_EQ("GET", error1.method); |
| 19266 | EXPECT_EQ(200, error1.status_code); |
| 19267 | EXPECT_EQ(OK, error1.type); |
| 19268 | EXPECT_EQ(0, error1.reporting_upload_depth); |
| 19269 | |
| 19270 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 19271 | network_error_logging_service()->errors()[1]; |
| 19272 | EXPECT_EQ(GURL("https://mail.example.org/"), error2.uri); |
| 19273 | EXPECT_TRUE(error2.referrer.is_empty()); |
| 19274 | EXPECT_EQ("", error2.user_agent); |
| 19275 | EXPECT_EQ(ip, error2.server_ip); |
| 19276 | EXPECT_EQ("h2", error2.protocol); |
| 19277 | EXPECT_EQ("GET", error2.method); |
| 19278 | EXPECT_EQ(421, error2.status_code); |
| 19279 | EXPECT_EQ(OK, error2.type); |
| 19280 | EXPECT_EQ(0, error2.reporting_upload_depth); |
| 19281 | |
| 19282 | const NetworkErrorLoggingService::RequestDetails& error3 = |
| 19283 | network_error_logging_service()->errors()[2]; |
| 19284 | EXPECT_EQ(GURL("https://mail.example.org/"), error3.uri); |
| 19285 | EXPECT_TRUE(error3.referrer.is_empty()); |
| 19286 | EXPECT_EQ("", error3.user_agent); |
| 19287 | EXPECT_EQ(ip, error3.server_ip); |
| 19288 | EXPECT_EQ("h2", error3.protocol); |
| 19289 | EXPECT_EQ("GET", error3.method); |
| 19290 | EXPECT_EQ(200, error3.status_code); |
| 19291 | EXPECT_EQ(OK, error3.type); |
| 19292 | EXPECT_EQ(0, error3.reporting_upload_depth); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19293 | } |
| 19294 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19295 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19296 | CreateReportCancelAfterStart) { |
| 19297 | StaticSocketDataProvider data; |
| 19298 | data.set_connect_data(MockConnect(SYNCHRONOUS, ERR_IO_PENDING)); |
| 19299 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19300 | |
| 19301 | TestCompletionCallback callback; |
| 19302 | auto session = CreateSession(&session_deps_); |
| 19303 | auto trans = |
| 19304 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19305 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19306 | EXPECT_EQ(rv, ERR_IO_PENDING); |
| 19307 | |
| 19308 | // Cancel after start. |
| 19309 | trans.reset(); |
| 19310 | |
| 19311 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19312 | CheckReport(0 /* index */, 0 /* status_code */, ERR_ABORTED, |
| 19313 | IPAddress() /* server_ip */); |
| 19314 | } |
| 19315 | |
| 19316 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19317 | CreateReportCancelBeforeReadingBody) { |
| 19318 | std::string extra_header_string = extra_headers_.ToString(); |
| 19319 | MockWrite data_writes[] = { |
| 19320 | MockWrite("GET / HTTP/1.1\r\n" |
| 19321 | "Host: www.example.org\r\n" |
| 19322 | "Connection: keep-alive\r\n"), |
| 19323 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19324 | }; |
| 19325 | MockRead data_reads[] = { |
| 19326 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 19327 | MockRead("Content-Length: 100\r\n\r\n"), // Body is never read. |
| 19328 | }; |
| 19329 | |
| 19330 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19331 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19332 | |
| 19333 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19334 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19335 | |
| 19336 | TestCompletionCallback callback; |
| 19337 | auto session = CreateSession(&session_deps_); |
| 19338 | auto trans = |
| 19339 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19340 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19341 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19342 | |
| 19343 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19344 | ASSERT_TRUE(response); |
| 19345 | |
| 19346 | EXPECT_TRUE(response->headers); |
| 19347 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 19348 | |
| 19349 | // Cancel before reading the body. |
| 19350 | trans.reset(); |
| 19351 | |
| 19352 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19353 | CheckReport(0 /* index */, 200 /* status_code */, ERR_ABORTED); |
| 19354 | } |
| 19355 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19356 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportHttp) { |
| 19357 | base::HistogramTester histograms; |
| 19358 | RequestPolicy(); |
| 19359 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19360 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19361 | |
| 19362 | // Make HTTP request |
| 19363 | std::string extra_header_string = extra_headers_.ToString(); |
| 19364 | MockRead data_reads[] = { |
| 19365 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 19366 | MockRead("hello world"), |
| 19367 | MockRead(SYNCHRONOUS, OK), |
| 19368 | }; |
| 19369 | MockWrite data_writes[] = { |
| 19370 | MockWrite("GET / HTTP/1.1\r\n" |
| 19371 | "Host: www.example.org\r\n" |
| 19372 | "Connection: keep-alive\r\n"), |
| 19373 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19374 | }; |
| 19375 | |
Lily Chen | d3930e7 | 2019-03-01 19:31:11 | [diff] [blame] | 19376 | StaticSocketDataProvider data(data_reads, data_writes); |
| 19377 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19378 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19379 | // Insecure url |
| 19380 | url_ = "http://www.example.org/"; |
| 19381 | request_.url = GURL(url_); |
| 19382 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19383 | TestCompletionCallback callback; |
| 19384 | auto session = CreateSession(&session_deps_); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19385 | auto trans = |
| 19386 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19387 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19388 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19389 | |
| 19390 | std::string response_data; |
| 19391 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19392 | EXPECT_EQ("hello world", response_data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19393 | |
| 19394 | // Insecure request does not generate a report |
| 19395 | histograms.ExpectBucketCount( |
| 19396 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
Tsuyoshi Horo | 0b04223 | 2019-03-06 01:11:05 | [diff] [blame] | 19397 | NetworkErrorLoggingService::RequestOutcome::kDiscardedInsecureOrigin, 1); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19398 | |
| 19399 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19400 | } |
| 19401 | |
| 19402 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19403 | DontCreateReportHttpError) { |
| 19404 | base::HistogramTester histograms; |
| 19405 | RequestPolicy(); |
| 19406 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19407 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19408 | |
| 19409 | // Make HTTP request that fails |
| 19410 | MockRead data_reads[] = { |
| 19411 | MockRead("hello world"), |
| 19412 | MockRead(SYNCHRONOUS, OK), |
| 19413 | }; |
| 19414 | |
| 19415 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
| 19416 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19417 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19418 | url_ = "http://www.originwithoutpolicy.com:2000/"; |
| 19419 | request_.url = GURL(url_); |
| 19420 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19421 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19422 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19423 | auto trans = |
| 19424 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19425 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19426 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19427 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 19428 | |
| 19429 | // Insecure request does not generate a report, regardless of existence of a |
| 19430 | // policy for the origin. |
| 19431 | histograms.ExpectBucketCount( |
| 19432 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
Tsuyoshi Horo | 0b04223 | 2019-03-06 01:11:05 | [diff] [blame] | 19433 | NetworkErrorLoggingService::RequestOutcome::kDiscardedInsecureOrigin, 1); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19434 | |
| 19435 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19436 | } |
| 19437 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 19438 | // Don't report on proxy auth challenges, don't report if connecting through a |
| 19439 | // proxy. |
| 19440 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportProxy) { |
| 19441 | HttpRequestInfo request; |
| 19442 | request.method = "GET"; |
| 19443 | request.url = GURL("https://www.example.org/"); |
| 19444 | request.traffic_annotation = |
| 19445 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19446 | |
| 19447 | // Configure against proxy server "myproxy:70". |
| 19448 | session_deps_.proxy_resolution_service = |
| 19449 | ProxyResolutionService::CreateFixedFromPacResult( |
| 19450 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19451 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19452 | |
| 19453 | // Since we have proxy, should try to establish tunnel. |
| 19454 | MockWrite data_writes1[] = { |
| 19455 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19456 | "Host: www.example.org:443\r\n" |
| 19457 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 19458 | }; |
| 19459 | |
| 19460 | // The proxy responds to the connect with a 407, using a non-persistent |
| 19461 | // connection. |
| 19462 | MockRead data_reads1[] = { |
| 19463 | // No credentials. |
| 19464 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 19465 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 19466 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 19467 | }; |
| 19468 | |
| 19469 | MockWrite data_writes2[] = { |
| 19470 | // After calling trans->RestartWithAuth(), this is the request we should |
| 19471 | // be issuing -- the final header line contains the credentials. |
| 19472 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19473 | "Host: www.example.org:443\r\n" |
| 19474 | "Proxy-Connection: keep-alive\r\n" |
| 19475 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 19476 | |
| 19477 | MockWrite("GET / HTTP/1.1\r\n" |
| 19478 | "Host: www.example.org\r\n" |
| 19479 | "Connection: keep-alive\r\n\r\n"), |
| 19480 | }; |
| 19481 | |
| 19482 | MockRead data_reads2[] = { |
| 19483 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 19484 | |
| 19485 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19486 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 19487 | MockRead("Content-Length: 5\r\n\r\n"), |
| 19488 | MockRead(SYNCHRONOUS, "hello"), |
| 19489 | }; |
| 19490 | |
| 19491 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19492 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19493 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 19494 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19495 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19496 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19497 | |
| 19498 | TestCompletionCallback callback1; |
| 19499 | |
| 19500 | auto trans = |
| 19501 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19502 | |
| 19503 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
| 19504 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19505 | |
| 19506 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19507 | EXPECT_EQ(407, response->headers->response_code()); |
| 19508 | |
| 19509 | std::string response_data; |
| 19510 | rv = ReadTransaction(trans.get(), &response_data); |
| 19511 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
| 19512 | |
| 19513 | // No NEL report is generated for the 407. |
| 19514 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 19515 | |
| 19516 | TestCompletionCallback callback2; |
| 19517 | |
| 19518 | rv = |
| 19519 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 19520 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19521 | |
| 19522 | response = trans->GetResponseInfo(); |
| 19523 | EXPECT_EQ(200, response->headers->response_code()); |
| 19524 | |
| 19525 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19526 | EXPECT_EQ("hello", response_data); |
| 19527 | |
| 19528 | trans.reset(); |
| 19529 | |
| 19530 | // No NEL report is generated because we are behind a proxy. |
| 19531 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 19532 | } |
| 19533 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19534 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19535 | ReportContainsUploadDepth) { |
| 19536 | reporting_upload_depth_ = 7; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19537 | request_.reporting_upload_depth = reporting_upload_depth_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19538 | RequestPolicy(); |
| 19539 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19540 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19541 | network_error_logging_service()->errors()[0]; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19542 | EXPECT_EQ(7, error.reporting_upload_depth); |
| 19543 | } |
| 19544 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19545 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ReportElapsedTime) { |
| 19546 | std::string extra_header_string = extra_headers_.ToString(); |
| 19547 | static const base::TimeDelta kSleepDuration = |
| 19548 | base::TimeDelta::FromMilliseconds(10); |
| 19549 | |
| 19550 | std::vector<MockWrite> data_writes = { |
| 19551 | MockWrite(ASYNC, 0, |
| 19552 | "GET / HTTP/1.1\r\n" |
| 19553 | "Host: www.example.org\r\n" |
| 19554 | "Connection: keep-alive\r\n"), |
| 19555 | MockWrite(ASYNC, 1, extra_header_string.data()), |
| 19556 | }; |
| 19557 | |
| 19558 | std::vector<MockRead> data_reads = { |
| 19559 | // Write one byte of the status line, followed by a pause. |
| 19560 | MockRead(ASYNC, 2, "H"), |
| 19561 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 19562 | MockRead(ASYNC, 4, "TTP/1.1 200 OK\r\n\r\n"), |
| 19563 | MockRead(ASYNC, 5, "hello world"), |
| 19564 | MockRead(SYNCHRONOUS, OK, 6), |
| 19565 | }; |
| 19566 | |
| 19567 | SequencedSocketData data(data_reads, data_writes); |
| 19568 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19569 | |
| 19570 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19571 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19572 | |
| 19573 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19574 | |
| 19575 | auto trans = |
| 19576 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19577 | |
| 19578 | TestCompletionCallback callback; |
| 19579 | |
| 19580 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19581 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19582 | |
| 19583 | data.RunUntilPaused(); |
| 19584 | ASSERT_TRUE(data.IsPaused()); |
| 19585 | FastForwardBy(kSleepDuration); |
| 19586 | data.Resume(); |
| 19587 | |
| 19588 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19589 | |
| 19590 | std::string response_data; |
| 19591 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19592 | EXPECT_EQ("hello world", response_data); |
| 19593 | |
| 19594 | trans.reset(); |
| 19595 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19596 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19597 | |
| 19598 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19599 | |
| 19600 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19601 | network_error_logging_service()->errors()[0]; |
| 19602 | |
| 19603 | // Sanity-check elapsed time in error report |
| 19604 | EXPECT_EQ(kSleepDuration, error.elapsed_time); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19605 | } |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19606 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19607 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 19608 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 19609 | } // namespace net |