[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" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 30 | #include "base/strings/utf_string_conversions.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 31 | #include "base/test/metrics/histogram_tester.h" |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 32 | #include "base/test/scoped_task_environment.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 33 | #include "base/test/simple_test_clock.h" |
| 34 | #include "base/test/simple_test_tick_clock.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 35 | #include "base/test/test_file_util.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 36 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 37 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 38 | #include "net/base/chunked_upload_data_stream.h" |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 39 | #include "net/base/completion_once_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 40 | #include "net/base/elements_upload_data_stream.h" |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 41 | #include "net/base/host_port_pair.h" |
Tsuyoshi Horo | 01faed6 | 2019-02-20 22:11:37 | [diff] [blame^] | 42 | #include "net/base/ip_endpoint.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 43 | #include "net/base/load_timing_info.h" |
| 44 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 45 | #include "net/base/net_errors.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 46 | #include "net/base/proxy_delegate.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 47 | #include "net/base/proxy_server.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 48 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 49 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 50 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 51 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 52 | #include "net/base/upload_file_element_reader.h" |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 53 | #include "net/cert/cert_status_flags.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 54 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 55 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 56 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 57 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 58 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 59 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 60 | #include "net/http/http_auth_scheme.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 61 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 62 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 63 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 64 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 65 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 66 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 67 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 68 | #include "net/http/http_stream_factory.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 69 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 70 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 71 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 72 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 73 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 74 | #include "net/log/test_net_log_entry.h" |
| 75 | #include "net/log/test_net_log_util.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 76 | #include "net/proxy_resolution/mock_proxy_resolver.h" |
| 77 | #include "net/proxy_resolution/proxy_config_service_fixed.h" |
| 78 | #include "net/proxy_resolution/proxy_info.h" |
Lily Houghton | ffe89daa0 | 2018-03-09 18:30:03 | [diff] [blame] | 79 | #include "net/proxy_resolution/proxy_resolution_service.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 80 | #include "net/proxy_resolution/proxy_resolver.h" |
| 81 | #include "net/proxy_resolution/proxy_resolver_factory.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 82 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 83 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 84 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 85 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 86 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 87 | #include "net/socket/next_proto.h" |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 88 | #include "net/socket/socket_tag.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 89 | #include "net/socket/socket_test_util.h" |
Matt Menke | 4b412da | 2019-01-25 19:31:12 | [diff] [blame] | 90 | #include "net/socket/socks_connect_job.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 91 | #include "net/socket/ssl_client_socket.h" |
Bence Béky | 94658bf | 2018-05-11 19:22:58 | [diff] [blame] | 92 | #include "net/spdy/spdy_session.h" |
| 93 | #include "net/spdy/spdy_session_pool.h" |
| 94 | #include "net/spdy/spdy_test_util_common.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 95 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 96 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 97 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 98 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 99 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 100 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 101 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 102 | #include "net/test/test_data_directory.h" |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 103 | #include "net/test/test_with_scoped_task_environment.h" |
Victor Vasiliev | 27cc771 | 2019-01-24 11:50:14 | [diff] [blame] | 104 | #include "net/third_party/quiche/src/spdy/core/spdy_framer.h" |
[email protected] | baee31a | 2018-01-18 06:10:23 | [diff] [blame] | 105 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 106 | #include "net/websockets/websocket_handshake_stream_base.h" |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 107 | #include "net/websockets/websocket_test_util.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 108 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 109 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 110 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 111 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 112 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 113 | #if defined(NTLM_PORTABLE) |
| 114 | #include "base/base64.h" |
| 115 | #include "net/ntlm/ntlm_test_data.h" |
| 116 | #endif |
| 117 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 118 | #if BUILDFLAG(ENABLE_REPORTING) |
| 119 | #include "net/network_error_logging/network_error_logging_service.h" |
| 120 | #include "net/network_error_logging/network_error_logging_test_util.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 121 | #include "net/reporting/reporting_cache.h" |
| 122 | #include "net/reporting/reporting_client.h" |
| 123 | #include "net/reporting/reporting_header_parser.h" |
| 124 | #include "net/reporting/reporting_service.h" |
| 125 | #include "net/reporting/reporting_test_util.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 126 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 127 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 128 | using net::test::IsError; |
| 129 | using net::test::IsOk; |
| 130 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 131 | using base::ASCIIToUTF16; |
| 132 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 133 | //----------------------------------------------------------------------------- |
| 134 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 135 | namespace net { |
| 136 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 137 | namespace { |
| 138 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 139 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 140 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 141 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 142 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 143 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 144 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 145 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 146 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 147 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 148 | const base::string16 kSecond(ASCIIToUTF16("second")); |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 149 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 150 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 151 | const char kAlternativeServiceHttpHeader[] = |
| 152 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 153 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 154 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 155 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 156 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 157 | } |
| 158 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 159 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 160 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 161 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 162 | } |
| 163 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 164 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 165 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 166 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 167 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 168 | if (!params) |
| 169 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 170 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 171 | if (!params->GetList("headers", &header_list)) |
| 172 | return false; |
| 173 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 174 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 175 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 176 | return true; |
| 177 | } |
| 178 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 179 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 180 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 181 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 182 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 183 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 184 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 185 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 186 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 187 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 188 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 189 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 190 | |
| 191 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 192 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 193 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 194 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 195 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 196 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 197 | } |
| 198 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 199 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 200 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 201 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 202 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 203 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 204 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 205 | |
| 206 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 207 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 208 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 209 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 210 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 211 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 212 | load_timing_info.send_start); |
| 213 | |
| 214 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 215 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 216 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 217 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 218 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 219 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 223 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 224 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 225 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 226 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 227 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 228 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 229 | |
| 230 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 231 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 232 | load_timing_info.proxy_resolve_end); |
| 233 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 234 | load_timing_info.send_start); |
| 235 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 236 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 237 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 238 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 239 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 240 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 244 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 245 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 246 | int connect_timing_flags) { |
| 247 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 248 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 249 | |
| 250 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 251 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 252 | load_timing_info.proxy_resolve_end); |
| 253 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 254 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 255 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 256 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 257 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 258 | load_timing_info.send_start); |
| 259 | |
| 260 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 261 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 262 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 263 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 264 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 265 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 266 | } |
| 267 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 268 | // ProxyResolver that records URLs passed to it, and that can be told what |
| 269 | // result to return. |
| 270 | class CapturingProxyResolver : public ProxyResolver { |
| 271 | public: |
| 272 | CapturingProxyResolver() |
| 273 | : proxy_server_(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 80)) {} |
| 274 | ~CapturingProxyResolver() override = default; |
| 275 | |
| 276 | int GetProxyForURL(const GURL& url, |
| 277 | ProxyInfo* results, |
| 278 | CompletionOnceCallback callback, |
| 279 | std::unique_ptr<Request>* request, |
| 280 | const NetLogWithSource& net_log) override { |
| 281 | results->UseProxyServer(proxy_server_); |
| 282 | resolved_.push_back(url); |
| 283 | return OK; |
| 284 | } |
| 285 | |
| 286 | // Sets whether the resolver should use direct connections, instead of a |
| 287 | // proxy. |
| 288 | void set_proxy_server(ProxyServer proxy_server) { |
| 289 | proxy_server_ = proxy_server; |
| 290 | } |
| 291 | |
| 292 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 293 | |
| 294 | private: |
| 295 | std::vector<GURL> resolved_; |
| 296 | |
| 297 | ProxyServer proxy_server_; |
| 298 | |
| 299 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 300 | }; |
| 301 | |
| 302 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 303 | public: |
| 304 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 305 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 306 | |
| 307 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 308 | std::unique_ptr<ProxyResolver>* resolver, |
| 309 | CompletionOnceCallback callback, |
| 310 | std::unique_ptr<Request>* request) override { |
| 311 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
| 312 | return OK; |
| 313 | } |
| 314 | |
| 315 | private: |
| 316 | ProxyResolver* resolver_; |
| 317 | }; |
| 318 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 319 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 320 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 321 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 322 | } |
| 323 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 324 | class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 325 | public: |
| 326 | FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 327 | |
| 328 | // ProxyResolverFactory override. |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 329 | int CreateProxyResolver(const scoped_refptr<PacFileData>& script_data, |
| 330 | std::unique_ptr<ProxyResolver>* result, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 331 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 332 | std::unique_ptr<Request>* request) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 333 | return ERR_PAC_SCRIPT_FAILED; |
| 334 | } |
| 335 | }; |
| 336 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 337 | class TestSSLConfigService : public SSLConfigService { |
| 338 | public: |
| 339 | explicit TestSSLConfigService(const SSLConfig& config) : config_(config) {} |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 340 | ~TestSSLConfigService() override = default; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 341 | |
| 342 | void GetSSLConfig(SSLConfig* config) override { *config = config_; } |
| 343 | |
Nick Harper | 89bc721 | 2018-07-31 19:07:57 | [diff] [blame] | 344 | bool CanShareConnectionWithClientCerts( |
| 345 | const std::string& hostname) const override { |
| 346 | return false; |
| 347 | } |
| 348 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 349 | private: |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 350 | SSLConfig config_; |
| 351 | }; |
| 352 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 353 | } // namespace |
| 354 | |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 355 | class HttpNetworkTransactionTest : public PlatformTest, |
| 356 | public WithScopedTaskEnvironment { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 357 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 358 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 359 | // Important to restore the per-pool limit first, since the pool limit must |
| 360 | // always be greater than group limit, and the tests reduce both limits. |
| 361 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 362 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 363 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 364 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 365 | } |
| 366 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 367 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 368 | HttpNetworkTransactionTest() |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 369 | : WithScopedTaskEnvironment( |
| 370 | base::test::ScopedTaskEnvironment::MainThreadType::IO_MOCK_TIME, |
| 371 | base::test::ScopedTaskEnvironment::NowSource:: |
| 372 | MAIN_THREAD_MOCK_TIME), |
| 373 | ssl_(ASYNC, OK), |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 374 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 375 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 376 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 377 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 378 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 379 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 380 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 381 | struct SimpleGetHelperResult { |
| 382 | int rv; |
| 383 | std::string status_line; |
| 384 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 385 | int64_t total_received_bytes; |
| 386 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 387 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 388 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 389 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 390 | }; |
| 391 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 392 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 393 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 394 | base::RunLoop().RunUntilIdle(); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 395 | // Set an initial delay to ensure that the first call to TimeTicks::Now() |
| 396 | // before incrementing the counter does not return a null value. |
| 397 | FastForwardBy(TimeDelta::FromSeconds(1)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 398 | } |
| 399 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 400 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 401 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 402 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 403 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 404 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 405 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 406 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 407 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 408 | } |
| 409 | |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 410 | void Check100ResponseTiming(bool use_spdy); |
| 411 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 412 | // Either |write_failure| specifies a write failure or |read_failure| |
| 413 | // specifies a read failure when using a reused socket. In either case, the |
| 414 | // failure should cause the network transaction to resend the request, and the |
| 415 | // other argument should be NULL. |
| 416 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 417 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 418 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 419 | // Either |write_failure| specifies a write failure or |read_failure| |
| 420 | // specifies a read failure when using a reused socket. In either case, the |
| 421 | // failure should cause the network transaction to resend the request, and the |
| 422 | // other argument should be NULL. |
| 423 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 424 | const MockRead* read_failure, |
| 425 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 426 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 427 | SimpleGetHelperResult SimpleGetHelperForData( |
| 428 | base::span<StaticSocketDataProvider*> providers) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 429 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 430 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 431 | HttpRequestInfo request; |
| 432 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 433 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 434 | request.traffic_annotation = |
| 435 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 436 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 437 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 438 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 439 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 440 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 441 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 442 | for (auto* provider : providers) { |
| 443 | session_deps_.socket_factory->AddSocketDataProvider(provider); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 444 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 445 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 446 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 447 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 448 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 449 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 450 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 451 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 452 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 453 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 454 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 455 | |
| 456 | // Even in the failure cases that use this function, connections are always |
| 457 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 458 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 459 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 460 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 461 | if (out.rv != OK) |
| 462 | return out; |
| 463 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 464 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 465 | // Can't use ASSERT_* inside helper functions like this, so |
| 466 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 467 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 468 | out.rv = ERR_UNEXPECTED; |
| 469 | return out; |
| 470 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 471 | out.status_line = response->headers->GetStatusLine(); |
| 472 | |
Tsuyoshi Horo | 01faed6 | 2019-02-20 22:11:37 | [diff] [blame^] | 473 | EXPECT_EQ("127.0.0.1", response->remote_endpoint.ToStringWithoutPort()); |
| 474 | EXPECT_EQ(80, response->remote_endpoint.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 475 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 476 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 477 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 478 | EXPECT_EQ(got_endpoint, |
| 479 | out.remote_endpoint_after_start.address().size() > 0); |
| 480 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 481 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 482 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 483 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 484 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 485 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 486 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 487 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 488 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 489 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 490 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 491 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 492 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 493 | std::string line; |
| 494 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 495 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 496 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 497 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 498 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 499 | std::string value; |
| 500 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 501 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 502 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 503 | EXPECT_EQ("keep-alive", value); |
| 504 | |
| 505 | std::string response_headers; |
| 506 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 507 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 508 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 509 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 510 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 511 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 512 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 513 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 514 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 515 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 516 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 517 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 518 | SimpleGetHelperResult SimpleGetHelper(base::span<const MockRead> data_reads) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 519 | MockWrite data_writes[] = { |
| 520 | MockWrite("GET / HTTP/1.1\r\n" |
| 521 | "Host: www.example.org\r\n" |
| 522 | "Connection: keep-alive\r\n\r\n"), |
| 523 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 524 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 525 | StaticSocketDataProvider reads(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 526 | StaticSocketDataProvider* data[] = {&reads}; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 527 | SimpleGetHelperResult out = SimpleGetHelperForData(data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 528 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 529 | EXPECT_EQ(CountWriteBytes(data_writes), out.total_sent_bytes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 530 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 531 | } |
| 532 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 533 | void AddSSLSocketData() { |
| 534 | ssl_.next_proto = kProtoHTTP2; |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 535 | ssl_.ssl_info.cert = |
| 536 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 537 | ASSERT_TRUE(ssl_.ssl_info.cert); |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 538 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 539 | } |
| 540 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 541 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 542 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 543 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 544 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 545 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 546 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 547 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 548 | // These clocks are defined here, even though they're only used in the |
| 549 | // Reporting tests below, since they need to be destroyed after |
| 550 | // |session_deps_|. |
| 551 | base::SimpleTestClock clock_; |
| 552 | base::SimpleTestTickClock tick_clock_; |
| 553 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 554 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 555 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 556 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 557 | |
| 558 | // Original socket limits. Some tests set these. Safest to always restore |
| 559 | // them once each test has been run. |
| 560 | int old_max_group_sockets_; |
| 561 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 562 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 563 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 564 | namespace { |
| 565 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 566 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 567 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 568 | BeforeHeadersSentHandler() |
| 569 | : observed_before_headers_sent_with_proxy_(false), |
| 570 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 571 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 572 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 573 | HttpRequestHeaders* request_headers) { |
| 574 | observed_before_headers_sent_ = true; |
| 575 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 576 | !proxy_info.is_quic()) { |
| 577 | return; |
| 578 | } |
| 579 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 580 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 581 | } |
| 582 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 583 | bool observed_before_headers_sent_with_proxy() const { |
| 584 | return observed_before_headers_sent_with_proxy_; |
| 585 | } |
| 586 | |
| 587 | bool observed_before_headers_sent() const { |
| 588 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | std::string observed_proxy_server_uri() const { |
| 592 | return observed_proxy_server_uri_; |
| 593 | } |
| 594 | |
| 595 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 596 | bool observed_before_headers_sent_with_proxy_; |
| 597 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 598 | std::string observed_proxy_server_uri_; |
| 599 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 600 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 601 | }; |
| 602 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 603 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 604 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 605 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 606 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 607 | const int sizeof_row = strlen(row); |
| 608 | const int num_rows = static_cast<int>( |
| 609 | ceil(static_cast<float>(size) / sizeof_row)); |
| 610 | const int sizeof_data = num_rows * sizeof_row; |
| 611 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 612 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 613 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 614 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 615 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 616 | } |
| 617 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 618 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 619 | uint64_t MockGetMSTime() { |
| 620 | // Tue, 23 May 2017 20:13:07 +0000 |
| 621 | return 131400439870000000; |
| 622 | } |
| 623 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 624 | // Alternative functions that eliminate randomness and dependency on the local |
| 625 | // host name so that the generated NTLM messages are reproducible. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 626 | void MockGenerateRandom(uint8_t* output, size_t n) { |
| 627 | // This is set to 0xaa because the client challenge for testing in |
| 628 | // [MS-NLMP] Section 4.2.1 is 8 bytes of 0xaa. |
| 629 | memset(output, 0xaa, n); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 630 | } |
| 631 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 632 | std::string MockGetHostName() { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 633 | return ntlm::test::kHostnameAscii; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 634 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 635 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 636 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 637 | template<typename ParentPool> |
| 638 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 639 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 640 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 641 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 642 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 643 | const std::string last_group_name_received() const { |
| 644 | return last_group_name_; |
| 645 | } |
| 646 | |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 647 | bool socket_requested() const { return socket_requested_; } |
| 648 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 649 | int RequestSocket(const std::string& group_name, |
| 650 | const void* socket_params, |
| 651 | RequestPriority priority, |
Paul Jensen | 8d6f87ec | 2018-01-13 00:46:54 | [diff] [blame] | 652 | const SocketTag& socket_tag, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 653 | ClientSocketPool::RespectLimits respect_limits, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 654 | ClientSocketHandle* handle, |
Bence Béky | 5a8662b | 2018-07-03 13:04:03 | [diff] [blame] | 655 | CompletionOnceCallback callback, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 656 | const NetLogWithSource& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 657 | last_group_name_ = group_name; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 658 | socket_requested_ = true; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 659 | return ERR_IO_PENDING; |
| 660 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 661 | void CancelRequest(const std::string& group_name, |
| 662 | ClientSocketHandle* handle) override {} |
| 663 | void ReleaseSocket(const std::string& group_name, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 664 | std::unique_ptr<StreamSocket> socket, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 665 | int id) override {} |
| 666 | void CloseIdleSockets() override {} |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 667 | void CloseIdleSocketsInGroup(const std::string& group_name) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 668 | int IdleSocketCount() const override { return 0; } |
| 669 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 670 | return 0; |
| 671 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 672 | LoadState GetLoadState(const std::string& group_name, |
| 673 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 674 | return LOAD_STATE_IDLE; |
| 675 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 676 | |
| 677 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 678 | std::string last_group_name_; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 679 | bool socket_requested_ = false; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 680 | }; |
| 681 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 682 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 683 | CaptureGroupNameTransportSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 684 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 685 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 686 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 687 | HostResolver* host_resolver, |
| 688 | CertVerifier* /* cert_verifier */) |
Matt Menke | cb77b540 | 2019-01-28 17:11:23 | [diff] [blame] | 689 | : ParentPool(0, |
| 690 | 0, |
Tarun Bansal | a763509 | 2019-02-20 10:00:59 | [diff] [blame] | 691 | base::TimeDelta(), |
Matt Menke | cb77b540 | 2019-01-28 17:11:23 | [diff] [blame] | 692 | NULL, |
| 693 | host_resolver, |
| 694 | NULL, |
| 695 | NULL, |
| 696 | NULL, |
| 697 | NULL, |
| 698 | NULL, |
Matt Menke | c94d97b | 2019-02-01 19:28:28 | [diff] [blame] | 699 | NULL, |
Matt Menke | 1751ba7 | 2019-02-09 02:23:46 | [diff] [blame] | 700 | NULL, |
Daniel McArdle | da3fa94 | 2019-02-15 16:41:21 | [diff] [blame] | 701 | NULL, |
Matt Menke | cb77b540 | 2019-01-28 17:11:23 | [diff] [blame] | 702 | NULL, |
| 703 | NULL, |
Matt Menke | fa9574f | 2019-01-28 18:55:27 | [diff] [blame] | 704 | NULL, |
Matt Menke | cb77b540 | 2019-01-28 17:11:23 | [diff] [blame] | 705 | NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 706 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 707 | //----------------------------------------------------------------------------- |
| 708 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 709 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 710 | // configured for common cases. |
| 711 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 712 | if (!auth_challenge) |
| 713 | return false; |
| 714 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 715 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 716 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 717 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 718 | return true; |
| 719 | } |
| 720 | |
| 721 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 722 | if (!auth_challenge) |
| 723 | return false; |
| 724 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 725 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 726 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 727 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 728 | return true; |
| 729 | } |
| 730 | |
| 731 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 732 | if (!auth_challenge) |
| 733 | return false; |
| 734 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 735 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 736 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 737 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 738 | return true; |
| 739 | } |
| 740 | |
| 741 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 742 | if (!auth_challenge) |
| 743 | return false; |
| 744 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 745 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 746 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 747 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 748 | return true; |
| 749 | } |
| 750 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 751 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 752 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 753 | if (!auth_challenge) |
| 754 | return false; |
| 755 | EXPECT_FALSE(auth_challenge->is_proxy); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 756 | EXPECT_EQ("https://server", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 757 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 758 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 759 | return true; |
| 760 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 761 | |
| 762 | bool CheckNTLMProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 763 | if (!auth_challenge) |
| 764 | return false; |
| 765 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 766 | EXPECT_EQ("http://server", auth_challenge->challenger.Serialize()); |
| 767 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 768 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
| 769 | return true; |
| 770 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 771 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 772 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 773 | } // namespace |
| 774 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 775 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 776 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 777 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 778 | } |
| 779 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 780 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 781 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 782 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 783 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 784 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 785 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 786 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 787 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 788 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 789 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 790 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 791 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 792 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 793 | |
| 794 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 795 | } |
| 796 | |
| 797 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 798 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 799 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 800 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 801 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 802 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 803 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 804 | EXPECT_THAT(out.rv, IsOk()); |
| 805 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 806 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 807 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 808 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 809 | } |
| 810 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 811 | // Response with no status line, and a weird port. Should fail by default. |
| 812 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 813 | MockRead data_reads[] = { |
| 814 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 815 | }; |
| 816 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 817 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 818 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 819 | |
| 820 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 821 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 822 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 823 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 824 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 825 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 826 | request.method = "GET"; |
| 827 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 828 | request.traffic_annotation = |
| 829 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 830 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 831 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 832 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 833 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 834 | } |
| 835 | |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 836 | // Tests that request info can be destroyed after the headers phase is complete. |
| 837 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoReadDestroyRequestInfo) { |
| 838 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 839 | auto trans = |
| 840 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 841 | |
| 842 | MockRead data_reads[] = { |
| 843 | MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Connection: keep-alive\r\n"), |
| 844 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, 0), |
| 845 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 846 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 847 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 848 | |
| 849 | TestCompletionCallback callback; |
| 850 | |
| 851 | { |
| 852 | auto request = std::make_unique<HttpRequestInfo>(); |
| 853 | request->method = "GET"; |
| 854 | request->url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 855 | request->traffic_annotation = |
| 856 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 857 | |
| 858 | int rv = |
| 859 | trans->Start(request.get(), callback.callback(), NetLogWithSource()); |
| 860 | |
| 861 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 862 | } // Let request info be destroyed. |
| 863 | |
| 864 | trans.reset(); |
| 865 | } |
| 866 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 867 | // Response with no status line, and a weird port. Option to allow weird ports |
| 868 | // enabled. |
| 869 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 870 | MockRead data_reads[] = { |
| 871 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 872 | }; |
| 873 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 874 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 875 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 876 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 877 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 878 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 879 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 880 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 881 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 882 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 883 | request.method = "GET"; |
| 884 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 885 | request.traffic_annotation = |
| 886 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 887 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 888 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 889 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 890 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 891 | |
| 892 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 893 | ASSERT_TRUE(info->headers); |
| 894 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 895 | |
| 896 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 897 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 898 | } |
| 899 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 900 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 901 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 902 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 903 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 904 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 905 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 906 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 907 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 908 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 909 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 910 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 911 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 915 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 916 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 917 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 918 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 919 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 920 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 921 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 922 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 923 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 924 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 925 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 929 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 930 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 931 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 932 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 933 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 934 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 935 | EXPECT_THAT(out.rv, IsOk()); |
| 936 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 937 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 938 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 939 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 943 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 944 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 945 | MockRead("\n"), |
| 946 | MockRead("\n"), |
| 947 | MockRead("Q"), |
| 948 | MockRead("J"), |
| 949 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 950 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 951 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 952 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 953 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 954 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 955 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 956 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 957 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 958 | } |
| 959 | |
| 960 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 961 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 962 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 963 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 964 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 965 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 966 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 967 | EXPECT_THAT(out.rv, IsOk()); |
| 968 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 969 | EXPECT_EQ("HTT", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 970 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 971 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 972 | } |
| 973 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 974 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 975 | // persistent connection. The response should still terminate since a 204 |
| 976 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 977 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 978 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 979 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 980 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 981 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 982 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 983 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 984 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 985 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 986 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 987 | EXPECT_EQ("", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 988 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 989 | int64_t response_size = reads_size - strlen(junk); |
| 990 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 991 | } |
| 992 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 993 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 994 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 995 | std::string final_chunk = "0\r\n\r\n"; |
| 996 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 997 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 998 | MockRead data_reads[] = { |
| 999 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 1000 | MockRead("5\r\nHello\r\n"), |
| 1001 | MockRead("1\r\n"), |
| 1002 | MockRead(" \r\n"), |
| 1003 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1004 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1005 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1006 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1007 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1008 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1009 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1010 | EXPECT_EQ("Hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1011 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1012 | int64_t response_size = reads_size - extra_data.size(); |
| 1013 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1014 | } |
| 1015 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1016 | // Next tests deal with http://crbug.com/56344. |
| 1017 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1018 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1019 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1020 | MockRead data_reads[] = { |
| 1021 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1022 | MockRead("Content-Length: 10\r\n"), |
| 1023 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1024 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1025 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1026 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1027 | } |
| 1028 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1029 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1030 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1031 | MockRead data_reads[] = { |
| 1032 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1033 | MockRead("Content-Length: 5\r\n"), |
| 1034 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1035 | MockRead("Hello"), |
| 1036 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1037 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1038 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1039 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1040 | EXPECT_EQ("Hello", out.response_data); |
| 1041 | } |
| 1042 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1043 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1044 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1045 | // More than 2 dupes. |
| 1046 | { |
| 1047 | MockRead data_reads[] = { |
| 1048 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1049 | MockRead("Content-Length: 5\r\n"), |
| 1050 | MockRead("Content-Length: 5\r\n"), |
| 1051 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1052 | MockRead("Hello"), |
| 1053 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1054 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1055 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1056 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1057 | EXPECT_EQ("Hello", out.response_data); |
| 1058 | } |
| 1059 | // HTTP/1.0 |
| 1060 | { |
| 1061 | MockRead data_reads[] = { |
| 1062 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1063 | MockRead("Content-Length: 5\r\n"), |
| 1064 | MockRead("Content-Length: 5\r\n"), |
| 1065 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1066 | MockRead("Hello"), |
| 1067 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1068 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1069 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1070 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1071 | EXPECT_EQ("Hello", out.response_data); |
| 1072 | } |
| 1073 | // 2 dupes and one mismatched. |
| 1074 | { |
| 1075 | MockRead data_reads[] = { |
| 1076 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1077 | MockRead("Content-Length: 10\r\n"), |
| 1078 | MockRead("Content-Length: 10\r\n"), |
| 1079 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1080 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1081 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1082 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1083 | } |
| 1084 | } |
| 1085 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1086 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1087 | MultipleContentLengthHeadersTransferEncoding) { |
| 1088 | MockRead data_reads[] = { |
| 1089 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1090 | MockRead("Content-Length: 666\r\n"), |
| 1091 | MockRead("Content-Length: 1337\r\n"), |
| 1092 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1093 | MockRead("5\r\nHello\r\n"), |
| 1094 | MockRead("1\r\n"), |
| 1095 | MockRead(" \r\n"), |
| 1096 | MockRead("5\r\nworld\r\n"), |
| 1097 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1098 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1099 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1100 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1101 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1102 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1103 | EXPECT_EQ("Hello world", out.response_data); |
| 1104 | } |
| 1105 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1106 | // Next tests deal with http://crbug.com/98895. |
| 1107 | |
| 1108 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1109 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1110 | MockRead data_reads[] = { |
| 1111 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1112 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1113 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1114 | MockRead("Hello"), |
| 1115 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1116 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1117 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1118 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1119 | EXPECT_EQ("Hello", out.response_data); |
| 1120 | } |
| 1121 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1122 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1123 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1124 | MockRead data_reads[] = { |
| 1125 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1126 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1127 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1128 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1129 | MockRead("Hello"), |
| 1130 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1131 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1132 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1133 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1134 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1135 | } |
| 1136 | |
| 1137 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1138 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1139 | MockRead data_reads[] = { |
| 1140 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1141 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1142 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1143 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1144 | MockRead("Hello"), |
| 1145 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1146 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1147 | EXPECT_THAT(out.rv, |
| 1148 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1149 | } |
| 1150 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1151 | // Checks that two identical Location headers result in no error. |
| 1152 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1153 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1154 | MockRead data_reads[] = { |
| 1155 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1156 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1157 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1158 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1159 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1160 | }; |
| 1161 | |
| 1162 | HttpRequestInfo request; |
| 1163 | request.method = "GET"; |
| 1164 | request.url = GURL("http://redirect.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1165 | request.traffic_annotation = |
| 1166 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1167 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1168 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1169 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1170 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1171 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1172 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1173 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1174 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1175 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1176 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1177 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1178 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1179 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1180 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1181 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1182 | ASSERT_TRUE(response); |
| 1183 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1184 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1185 | std::string url; |
| 1186 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1187 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1188 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1189 | } |
| 1190 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1191 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1192 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1193 | MockRead data_reads[] = { |
| 1194 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1195 | MockRead("Location: http://good.com/\r\n"), |
| 1196 | MockRead("Location: http://evil.com/\r\n"), |
| 1197 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1198 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1199 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1200 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1201 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1202 | } |
| 1203 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1204 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1205 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1206 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1207 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1208 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1209 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1210 | request.traffic_annotation = |
| 1211 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1212 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1213 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1214 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1215 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1216 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1217 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1218 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1219 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1220 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1221 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1222 | "Host: www.example.org\r\n" |
| 1223 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1224 | }; |
| 1225 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1226 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1227 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1228 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1229 | // No response body because the test stops reading here. |
| 1230 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1231 | }; |
| 1232 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1233 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1234 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1235 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1236 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1237 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1238 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1239 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1240 | |
| 1241 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1242 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1243 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1244 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1245 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1246 | |
| 1247 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1248 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1249 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1250 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1251 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1252 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1253 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1254 | |
| 1255 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1256 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1257 | bool has_server_header = response->headers->EnumerateHeader( |
| 1258 | &iter, "Server", &server_header); |
| 1259 | EXPECT_TRUE(has_server_header); |
| 1260 | EXPECT_EQ("Blah", server_header); |
| 1261 | |
| 1262 | // Reading should give EOF right away, since there is no message body |
| 1263 | // (despite non-zero content-length). |
| 1264 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1265 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1266 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1267 | EXPECT_EQ("", response_data); |
| 1268 | } |
| 1269 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1270 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1271 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1272 | |
| 1273 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1274 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1275 | MockRead("hello"), |
| 1276 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1277 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1278 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1279 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1280 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1281 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1282 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1283 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1284 | "hello", "world" |
| 1285 | }; |
| 1286 | |
| 1287 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1288 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1289 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1290 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1291 | request.traffic_annotation = |
| 1292 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1293 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1294 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1295 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1296 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1297 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1298 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1299 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1300 | |
| 1301 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1302 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1303 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1304 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1305 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1306 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1307 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1308 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1309 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1310 | |
| 1311 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1312 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1313 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1314 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1315 | } |
| 1316 | } |
| 1317 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1318 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1319 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1320 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1321 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1322 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1323 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1324 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1325 | request.method = "POST"; |
| 1326 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1327 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1328 | request.traffic_annotation = |
| 1329 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1330 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1331 | // Check the upload progress returned before initialization is correct. |
| 1332 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1333 | EXPECT_EQ(0u, progress.size()); |
| 1334 | EXPECT_EQ(0u, progress.position()); |
| 1335 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1336 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1337 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1338 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1339 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1340 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1341 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1342 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1343 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1344 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1345 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1346 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1347 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1348 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1349 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1350 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1351 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1352 | |
| 1353 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1354 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1355 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1356 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1357 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1358 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1359 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1360 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1361 | |
| 1362 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1363 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1364 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1365 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1366 | } |
| 1367 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1368 | // This test is almost the same as Ignores100 above, but the response contains |
| 1369 | // 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] | 1370 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1371 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1372 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1373 | request.method = "GET"; |
| 1374 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1375 | request.traffic_annotation = |
| 1376 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1377 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1378 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1379 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1380 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1381 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1382 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1383 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1384 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1385 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1386 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1387 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1388 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1389 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1390 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1391 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1392 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1393 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1394 | |
| 1395 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1396 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1397 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1398 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1399 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1400 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1401 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1402 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1403 | |
| 1404 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1405 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1406 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1407 | EXPECT_EQ("hello world", response_data); |
| 1408 | } |
| 1409 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1410 | TEST_F(HttpNetworkTransactionTest, LoadTimingMeasuresTimeToFirstByteForHttp) { |
| 1411 | static const base::TimeDelta kDelayAfterFirstByte = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1412 | base::TimeDelta::FromMilliseconds(10); |
| 1413 | |
| 1414 | HttpRequestInfo request; |
| 1415 | request.method = "GET"; |
| 1416 | request.url = GURL("http://www.foo.com/"); |
| 1417 | request.traffic_annotation = |
| 1418 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1419 | |
| 1420 | std::vector<MockWrite> data_writes = { |
| 1421 | MockWrite(ASYNC, 0, |
| 1422 | "GET / HTTP/1.1\r\n" |
| 1423 | "Host: www.foo.com\r\n" |
| 1424 | "Connection: keep-alive\r\n\r\n"), |
| 1425 | }; |
| 1426 | |
| 1427 | std::vector<MockRead> data_reads = { |
| 1428 | // Write one byte of the status line, followed by a pause. |
| 1429 | MockRead(ASYNC, 1, "H"), |
| 1430 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1431 | MockRead(ASYNC, 3, "TTP/1.1 200 OK\r\n\r\n"), |
| 1432 | MockRead(ASYNC, 4, "hello world"), |
| 1433 | MockRead(SYNCHRONOUS, OK, 5), |
| 1434 | }; |
| 1435 | |
| 1436 | SequencedSocketData data(data_reads, data_writes); |
| 1437 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1438 | |
| 1439 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1440 | |
| 1441 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1442 | |
| 1443 | TestCompletionCallback callback; |
| 1444 | |
| 1445 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1446 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1447 | |
| 1448 | data.RunUntilPaused(); |
| 1449 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1450 | FastForwardBy(kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1451 | data.Resume(); |
| 1452 | |
| 1453 | rv = callback.WaitForResult(); |
| 1454 | EXPECT_THAT(rv, IsOk()); |
| 1455 | |
| 1456 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1457 | ASSERT_TRUE(response); |
| 1458 | |
| 1459 | EXPECT_TRUE(response->headers); |
| 1460 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1461 | |
| 1462 | LoadTimingInfo load_timing_info; |
| 1463 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1464 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1465 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1466 | // Ensure we didn't include the delay in the TTFB time. |
| 1467 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1468 | load_timing_info.connect_timing.connect_end); |
| 1469 | // Ensure that the mock clock advanced at all. |
| 1470 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1471 | kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1472 | |
| 1473 | std::string response_data; |
| 1474 | rv = ReadTransaction(&trans, &response_data); |
| 1475 | EXPECT_THAT(rv, IsOk()); |
| 1476 | EXPECT_EQ("hello world", response_data); |
| 1477 | } |
| 1478 | |
| 1479 | // Tests that the time-to-first-byte reported in a transaction's load timing |
| 1480 | // info uses the first response, even if 1XX/informational. |
| 1481 | void HttpNetworkTransactionTest::Check100ResponseTiming(bool use_spdy) { |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1482 | static const base::TimeDelta kDelayAfter100Response = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1483 | base::TimeDelta::FromMilliseconds(10); |
| 1484 | |
| 1485 | HttpRequestInfo request; |
| 1486 | request.method = "GET"; |
| 1487 | request.url = GURL("https://www.foo.com/"); |
| 1488 | request.traffic_annotation = |
| 1489 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1490 | |
| 1491 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 1492 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 1493 | |
| 1494 | std::vector<MockWrite> data_writes; |
| 1495 | std::vector<MockRead> data_reads; |
| 1496 | |
| 1497 | spdy::SpdySerializedFrame spdy_req( |
| 1498 | spdy_util_.ConstructSpdyGet(request.url.spec().c_str(), 1, LOWEST)); |
| 1499 | |
| 1500 | spdy::SpdyHeaderBlock spdy_resp1_headers; |
| 1501 | spdy_resp1_headers[spdy::kHttp2StatusHeader] = "100"; |
| 1502 | spdy::SpdySerializedFrame spdy_resp1( |
| 1503 | spdy_util_.ConstructSpdyReply(1, spdy_resp1_headers.Clone())); |
| 1504 | spdy::SpdySerializedFrame spdy_resp2( |
| 1505 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1506 | spdy::SpdySerializedFrame spdy_data( |
| 1507 | spdy_util_.ConstructSpdyDataFrame(1, "hello world", true)); |
| 1508 | |
| 1509 | if (use_spdy) { |
| 1510 | ssl.next_proto = kProtoHTTP2; |
| 1511 | |
| 1512 | data_writes = {CreateMockWrite(spdy_req, 0)}; |
| 1513 | |
| 1514 | data_reads = { |
| 1515 | CreateMockRead(spdy_resp1, 1), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1516 | CreateMockRead(spdy_resp2, 3), CreateMockRead(spdy_data, 4), |
| 1517 | MockRead(SYNCHRONOUS, OK, 5), |
| 1518 | }; |
| 1519 | } else { |
| 1520 | data_writes = { |
| 1521 | MockWrite(ASYNC, 0, |
| 1522 | "GET / HTTP/1.1\r\n" |
| 1523 | "Host: www.foo.com\r\n" |
| 1524 | "Connection: keep-alive\r\n\r\n"), |
| 1525 | }; |
| 1526 | |
| 1527 | data_reads = { |
| 1528 | MockRead(ASYNC, 1, "HTTP/1.1 100 Continue\r\n\r\n"), |
| 1529 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1530 | |
| 1531 | MockRead(ASYNC, 3, "HTTP/1.1 200 OK\r\n\r\n"), |
| 1532 | MockRead(ASYNC, 4, "hello world"), |
| 1533 | MockRead(SYNCHRONOUS, OK, 5), |
| 1534 | }; |
| 1535 | } |
| 1536 | |
| 1537 | SequencedSocketData data(data_reads, data_writes); |
| 1538 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1539 | |
| 1540 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1541 | |
| 1542 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1543 | |
| 1544 | TestCompletionCallback callback; |
| 1545 | |
| 1546 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1547 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1548 | |
| 1549 | data.RunUntilPaused(); |
| 1550 | // We should now have parsed the 100 response and hit ERR_IO_PENDING. Insert |
| 1551 | // the delay before parsing the 200 response. |
| 1552 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1553 | FastForwardBy(kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1554 | data.Resume(); |
| 1555 | |
| 1556 | rv = callback.WaitForResult(); |
| 1557 | EXPECT_THAT(rv, IsOk()); |
| 1558 | |
| 1559 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1560 | ASSERT_TRUE(response); |
| 1561 | |
| 1562 | LoadTimingInfo load_timing_info; |
| 1563 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1564 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1565 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1566 | // Ensure we didn't include the delay in the TTFB time. |
| 1567 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1568 | load_timing_info.connect_timing.connect_end); |
| 1569 | // Ensure that the mock clock advanced at all. |
| 1570 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1571 | kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1572 | |
| 1573 | std::string response_data; |
| 1574 | rv = ReadTransaction(&trans, &response_data); |
| 1575 | EXPECT_THAT(rv, IsOk()); |
| 1576 | EXPECT_EQ("hello world", response_data); |
| 1577 | } |
| 1578 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1579 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForHttp) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1580 | Check100ResponseTiming(false /* use_spdy */); |
| 1581 | } |
| 1582 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1583 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForSpdy) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1584 | Check100ResponseTiming(true /* use_spdy */); |
| 1585 | } |
| 1586 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1587 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1588 | HttpRequestInfo request; |
| 1589 | request.method = "POST"; |
| 1590 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1591 | request.traffic_annotation = |
| 1592 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1593 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1594 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1595 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1596 | |
| 1597 | MockRead data_reads[] = { |
| 1598 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1599 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1600 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1601 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1602 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1603 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1604 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1605 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1606 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1607 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1608 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1609 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1610 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1611 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1612 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1613 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1614 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1615 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1616 | } |
| 1617 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1618 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1619 | HttpRequestInfo request; |
| 1620 | request.method = "POST"; |
| 1621 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1622 | request.traffic_annotation = |
| 1623 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1624 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1625 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1626 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1627 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1628 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1629 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1630 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1631 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1632 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1633 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1634 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1635 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1636 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1637 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1638 | |
| 1639 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1640 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1641 | } |
| 1642 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1643 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1644 | const MockWrite* write_failure, |
| 1645 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1646 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1647 | request.method = "GET"; |
| 1648 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1649 | request.traffic_annotation = |
| 1650 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1651 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1652 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1653 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1654 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1655 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1656 | // Written data for successfully sending both requests. |
| 1657 | MockWrite data1_writes[] = { |
| 1658 | MockWrite("GET / HTTP/1.1\r\n" |
| 1659 | "Host: www.foo.com\r\n" |
| 1660 | "Connection: keep-alive\r\n\r\n"), |
| 1661 | MockWrite("GET / HTTP/1.1\r\n" |
| 1662 | "Host: www.foo.com\r\n" |
| 1663 | "Connection: keep-alive\r\n\r\n") |
| 1664 | }; |
| 1665 | |
| 1666 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1667 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1668 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1669 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1670 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1671 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1672 | |
| 1673 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1674 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1675 | data1_writes[1] = *write_failure; |
| 1676 | } else { |
| 1677 | ASSERT_TRUE(read_failure); |
| 1678 | data1_reads[2] = *read_failure; |
| 1679 | } |
| 1680 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1681 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1682 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1683 | |
| 1684 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1685 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1686 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1687 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1688 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1689 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1690 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1691 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1692 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1693 | "hello", "world" |
| 1694 | }; |
| 1695 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1696 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1697 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1698 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1699 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1700 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1701 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1702 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1703 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1704 | |
| 1705 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1706 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1707 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1708 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1709 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1710 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1711 | if (i == 0) { |
| 1712 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1713 | } else { |
| 1714 | // The second request should be using a new socket. |
| 1715 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1716 | } |
| 1717 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1718 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1719 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1720 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1721 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1722 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1723 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1724 | |
| 1725 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1726 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1727 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1728 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1729 | } |
| 1730 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1731 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1732 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1733 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1734 | const MockRead* read_failure, |
| 1735 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1736 | HttpRequestInfo request; |
| 1737 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1738 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1739 | request.traffic_annotation = |
| 1740 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1741 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1742 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1743 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1744 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1745 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1746 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1747 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1748 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1749 | ssl1.next_proto = kProtoHTTP2; |
| 1750 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1751 | } |
| 1752 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1753 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1754 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1755 | // SPDY versions of the request and response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1756 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1757 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1758 | spdy::SpdySerializedFrame spdy_response( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1759 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1760 | spdy::SpdySerializedFrame spdy_data( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 1761 | spdy_util_.ConstructSpdyDataFrame(1, "hello", true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1762 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1763 | // HTTP/1.1 versions of the request and response. |
| 1764 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1765 | "Host: www.foo.com\r\n" |
| 1766 | "Connection: keep-alive\r\n\r\n"; |
| 1767 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1768 | const char kHttpData[] = "hello"; |
| 1769 | |
| 1770 | std::vector<MockRead> data1_reads; |
| 1771 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1772 | if (write_failure) { |
| 1773 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1774 | data1_writes.push_back(*write_failure); |
| 1775 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1776 | } else { |
| 1777 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1778 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1779 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1780 | } else { |
| 1781 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1782 | } |
| 1783 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1784 | } |
| 1785 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1786 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1787 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1788 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1789 | std::vector<MockRead> data2_reads; |
| 1790 | std::vector<MockWrite> data2_writes; |
| 1791 | |
| 1792 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1793 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1794 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1795 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1796 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1797 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1798 | } else { |
| 1799 | data2_writes.push_back( |
| 1800 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1801 | |
| 1802 | data2_reads.push_back( |
| 1803 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1804 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1805 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1806 | } |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1807 | SequencedSocketData data2(data2_reads, data2_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1808 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1809 | |
| 1810 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1811 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1812 | // Wait for the preconnect to complete. |
| 1813 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1814 | base::RunLoop().RunUntilIdle(); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 1815 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1816 | |
| 1817 | // Make the request. |
| 1818 | TestCompletionCallback callback; |
| 1819 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1820 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1821 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1822 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1823 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1824 | |
| 1825 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1826 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1827 | |
| 1828 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1829 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1830 | TestLoadTimingNotReused( |
| 1831 | load_timing_info, |
| 1832 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1833 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1834 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1835 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1836 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1837 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1838 | if (response->was_fetched_via_spdy) { |
| 1839 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1840 | } else { |
| 1841 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1842 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1843 | |
| 1844 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1845 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1846 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1847 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1848 | } |
| 1849 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1850 | // Test that we do not retry indefinitely when a server sends an error like |
| 1851 | // ERR_SPDY_PING_FAILED, ERR_SPDY_SERVER_REFUSED_STREAM, |
| 1852 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1853 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1854 | HttpRequestInfo request; |
| 1855 | request.method = "GET"; |
| 1856 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1857 | request.traffic_annotation = |
| 1858 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1859 | |
| 1860 | // Check whether we give up after the third try. |
| 1861 | |
| 1862 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1863 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1864 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1865 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1866 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1867 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1868 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1869 | |
| 1870 | // Three go away responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1871 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1872 | StaticSocketDataProvider data2(data_read1, data_write); |
| 1873 | StaticSocketDataProvider data3(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1874 | |
| 1875 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1876 | AddSSLSocketData(); |
| 1877 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1878 | AddSSLSocketData(); |
| 1879 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1880 | AddSSLSocketData(); |
| 1881 | |
| 1882 | TestCompletionCallback callback; |
| 1883 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1884 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1885 | |
| 1886 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1887 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1888 | |
| 1889 | rv = callback.WaitForResult(); |
| 1890 | EXPECT_THAT(rv, IsError(ERR_SPDY_SERVER_REFUSED_STREAM)); |
| 1891 | } |
| 1892 | |
| 1893 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1894 | HttpRequestInfo request; |
| 1895 | request.method = "GET"; |
| 1896 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1897 | request.traffic_annotation = |
| 1898 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1899 | |
| 1900 | // Check whether we try atleast thrice before giving up. |
| 1901 | |
| 1902 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1903 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1904 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1905 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1906 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1907 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1908 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1909 | |
| 1910 | // Construct a non error HTTP2 response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1911 | spdy::SpdySerializedFrame spdy_response_no_error( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1912 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1913 | spdy::SpdySerializedFrame spdy_data( |
| 1914 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1915 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1916 | CreateMockRead(spdy_data, 2)}; |
| 1917 | |
| 1918 | // Two error responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1919 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1920 | StaticSocketDataProvider data2(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1921 | // Followed by a success response. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1922 | SequencedSocketData data3(data_read2, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1923 | |
| 1924 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1925 | AddSSLSocketData(); |
| 1926 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1927 | AddSSLSocketData(); |
| 1928 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1929 | AddSSLSocketData(); |
| 1930 | |
| 1931 | TestCompletionCallback callback; |
| 1932 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1933 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1934 | |
| 1935 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1936 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1937 | |
| 1938 | rv = callback.WaitForResult(); |
| 1939 | EXPECT_THAT(rv, IsOk()); |
| 1940 | } |
| 1941 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1942 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1943 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1944 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1945 | } |
| 1946 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1947 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1948 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1949 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1950 | } |
| 1951 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1952 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1953 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1954 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1955 | } |
| 1956 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1957 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1958 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1959 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1960 | MockRead read_failure(SYNCHRONOUS, |
| 1961 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1962 | "Connection: Keep-Alive\r\n" |
| 1963 | "Content-Length: 6\r\n\r\n" |
| 1964 | "Pickle"); |
| 1965 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1966 | } |
| 1967 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1968 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1969 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1970 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1971 | } |
| 1972 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1973 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1974 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1975 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1976 | } |
| 1977 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1978 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1979 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1980 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1981 | } |
| 1982 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1983 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1984 | MockRead read_failure(ASYNC, OK); // EOF |
| 1985 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1986 | } |
| 1987 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1988 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1989 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1990 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1991 | MockRead read_failure(SYNCHRONOUS, |
| 1992 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1993 | "Connection: Keep-Alive\r\n" |
| 1994 | "Content-Length: 6\r\n\r\n" |
| 1995 | "Pickle"); |
| 1996 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1997 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1998 | } |
| 1999 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2000 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2001 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 2002 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 2003 | } |
| 2004 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2005 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2006 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 2007 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 2008 | } |
| 2009 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2010 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2011 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 2012 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 2013 | } |
| 2014 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2015 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2016 | MockRead read_failure(ASYNC, OK); // EOF |
| 2017 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2018 | } |
| 2019 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2020 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2021 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2022 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2023 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2024 | request.traffic_annotation = |
| 2025 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2026 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2027 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2028 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2029 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2030 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2031 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2032 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2033 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2034 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2035 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2036 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2037 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2038 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2039 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2040 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2041 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2042 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2043 | |
| 2044 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2045 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2046 | |
| 2047 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2048 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2049 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2050 | } |
| 2051 | |
| 2052 | // What do various browsers do when the server closes a non-keepalive |
| 2053 | // connection without sending any response header or body? |
| 2054 | // |
| 2055 | // IE7: error page |
| 2056 | // Safari 3.1.2 (Windows): error page |
| 2057 | // Firefox 3.0.1: blank page |
| 2058 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2059 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 2060 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2061 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2062 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2063 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2064 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2065 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2066 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2067 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2068 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2069 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2070 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 2071 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2072 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 2073 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 2074 | // destructor in such situations. |
| 2075 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2076 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2077 | HttpRequestInfo request; |
| 2078 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2079 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2080 | request.traffic_annotation = |
| 2081 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2082 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2083 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2084 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2085 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2086 | |
| 2087 | MockRead data_reads[] = { |
| 2088 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2089 | MockRead("Connection: keep-alive\r\n"), |
| 2090 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2091 | MockRead("hello"), |
| 2092 | MockRead(SYNCHRONOUS, 0), |
| 2093 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2094 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2095 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2096 | |
| 2097 | TestCompletionCallback callback; |
| 2098 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2099 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2100 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2101 | |
| 2102 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2103 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2104 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2105 | scoped_refptr<IOBufferWithSize> io_buf = |
| 2106 | base::MakeRefCounted<IOBufferWithSize>(100); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2107 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2108 | if (rv == ERR_IO_PENDING) |
| 2109 | rv = callback.WaitForResult(); |
| 2110 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2111 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2112 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2113 | |
| 2114 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2115 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2116 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2117 | } |
| 2118 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2119 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2120 | HttpRequestInfo request; |
| 2121 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2122 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2123 | request.traffic_annotation = |
| 2124 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2125 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2126 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2127 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2128 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2129 | |
| 2130 | MockRead data_reads[] = { |
| 2131 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2132 | MockRead("Connection: keep-alive\r\n"), |
| 2133 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2134 | MockRead(SYNCHRONOUS, 0), |
| 2135 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2136 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2137 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2138 | |
| 2139 | TestCompletionCallback callback; |
| 2140 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2141 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2142 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2143 | |
| 2144 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2145 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2146 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2147 | scoped_refptr<IOBufferWithSize> io_buf( |
| 2148 | base::MakeRefCounted<IOBufferWithSize>(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2149 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2150 | if (rv == ERR_IO_PENDING) |
| 2151 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2152 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2153 | |
| 2154 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2155 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2156 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2157 | } |
| 2158 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2159 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 2160 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2161 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2162 | HttpRequestInfo request; |
| 2163 | request.method = "GET"; |
| 2164 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2165 | request.traffic_annotation = |
| 2166 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2167 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2168 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2169 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2170 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2171 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2172 | const char* request_data = |
| 2173 | "GET / HTTP/1.1\r\n" |
| 2174 | "Host: www.foo.com\r\n" |
| 2175 | "Connection: keep-alive\r\n\r\n"; |
| 2176 | MockWrite data_writes[] = { |
| 2177 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 2178 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 2179 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 2180 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 2181 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 2182 | }; |
| 2183 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2184 | // Note that because all these reads happen in the same |
| 2185 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 2186 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2187 | MockRead data_reads[] = { |
| 2188 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 2189 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 2190 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 2191 | MockRead(ASYNC, 7, |
| 2192 | "HTTP/1.1 302 Found\r\n" |
| 2193 | "Content-Length: 0\r\n\r\n"), |
| 2194 | MockRead(ASYNC, 9, |
| 2195 | "HTTP/1.1 302 Found\r\n" |
| 2196 | "Content-Length: 5\r\n\r\n" |
| 2197 | "hello"), |
| 2198 | MockRead(ASYNC, 11, |
| 2199 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2200 | "Content-Length: 0\r\n\r\n"), |
| 2201 | MockRead(ASYNC, 13, |
| 2202 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2203 | "Content-Length: 5\r\n\r\n" |
| 2204 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2205 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2206 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 2207 | // the set_busy_before_sync_reads(true) call, while the |
| 2208 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 2209 | // reuseable. See http://crbug.com/544255. |
| 2210 | MockRead(ASYNC, 15, |
| 2211 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2212 | "Content-Length: 5\r\n\r\n"), |
| 2213 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2214 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2215 | MockRead(ASYNC, 18, |
| 2216 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2217 | "Content-Length: 5\r\n\r\n" |
| 2218 | "he"), |
| 2219 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 2220 | |
| 2221 | // The body of the final request is actually read. |
| 2222 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 2223 | MockRead(ASYNC, 22, "hello"), |
| 2224 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2225 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2226 | data.set_busy_before_sync_reads(true); |
| 2227 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2228 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2229 | const int kNumUnreadBodies = base::size(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2230 | std::string response_lines[kNumUnreadBodies]; |
| 2231 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 2232 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2233 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2234 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2235 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2236 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2237 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2238 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2239 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2240 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2241 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2242 | LoadTimingInfo load_timing_info; |
| 2243 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2244 | if (i == 0) { |
| 2245 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2246 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2247 | } else { |
| 2248 | TestLoadTimingReused(load_timing_info); |
| 2249 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2250 | } |
| 2251 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2252 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2253 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2254 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2255 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2256 | response_lines[i] = response->headers->GetStatusLine(); |
| 2257 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2258 | // Delete the transaction without reading the response bodies. Then spin |
| 2259 | // the message loop, so the response bodies are drained. |
| 2260 | trans.reset(); |
| 2261 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2262 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2263 | |
| 2264 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2265 | "HTTP/1.1 204 No Content", |
| 2266 | "HTTP/1.1 205 Reset Content", |
| 2267 | "HTTP/1.1 304 Not Modified", |
| 2268 | "HTTP/1.1 302 Found", |
| 2269 | "HTTP/1.1 302 Found", |
| 2270 | "HTTP/1.1 301 Moved Permanently", |
| 2271 | "HTTP/1.1 301 Moved Permanently", |
| 2272 | "HTTP/1.1 200 Hunky-Dory", |
| 2273 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2274 | }; |
| 2275 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2276 | static_assert(kNumUnreadBodies == base::size(kStatusLines), |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2277 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2278 | |
| 2279 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2280 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2281 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2282 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2283 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2284 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2285 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2286 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2287 | ASSERT_TRUE(response); |
| 2288 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2289 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2290 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2291 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2292 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2293 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2294 | } |
| 2295 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2296 | // Sockets that receive extra data after a response is complete should not be |
| 2297 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2298 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2299 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2300 | MockWrite data_writes1[] = { |
| 2301 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2302 | "Host: www.borked.com\r\n" |
| 2303 | "Connection: keep-alive\r\n\r\n"), |
| 2304 | }; |
| 2305 | |
| 2306 | MockRead data_reads1[] = { |
| 2307 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2308 | "Connection: keep-alive\r\n" |
| 2309 | "Content-Length: 22\r\n\r\n" |
| 2310 | "This server is borked."), |
| 2311 | }; |
| 2312 | |
| 2313 | MockWrite data_writes2[] = { |
| 2314 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2315 | "Host: www.borked.com\r\n" |
| 2316 | "Connection: keep-alive\r\n\r\n"), |
| 2317 | }; |
| 2318 | |
| 2319 | MockRead data_reads2[] = { |
| 2320 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2321 | "Content-Length: 3\r\n\r\n" |
| 2322 | "foo"), |
| 2323 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2324 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2325 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2326 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2327 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2328 | |
| 2329 | TestCompletionCallback callback; |
| 2330 | HttpRequestInfo request1; |
| 2331 | request1.method = "HEAD"; |
| 2332 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2333 | request1.traffic_annotation = |
| 2334 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2335 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2336 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2337 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2338 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2339 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2340 | |
| 2341 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2342 | ASSERT_TRUE(response1); |
| 2343 | ASSERT_TRUE(response1->headers); |
| 2344 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2345 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2346 | |
| 2347 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2348 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2349 | EXPECT_EQ("", response_data1); |
| 2350 | // Deleting the transaction attempts to release the socket back into the |
| 2351 | // socket pool. |
| 2352 | trans1.reset(); |
| 2353 | |
| 2354 | HttpRequestInfo request2; |
| 2355 | request2.method = "GET"; |
| 2356 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2357 | request2.traffic_annotation = |
| 2358 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2359 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2360 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2361 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2362 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2363 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2364 | |
| 2365 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2366 | ASSERT_TRUE(response2); |
| 2367 | ASSERT_TRUE(response2->headers); |
| 2368 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2369 | |
| 2370 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2371 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2372 | EXPECT_EQ("foo", response_data2); |
| 2373 | } |
| 2374 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2375 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2376 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2377 | MockWrite data_writes1[] = { |
| 2378 | MockWrite("GET / HTTP/1.1\r\n" |
| 2379 | "Host: www.borked.com\r\n" |
| 2380 | "Connection: keep-alive\r\n\r\n"), |
| 2381 | }; |
| 2382 | |
| 2383 | MockRead data_reads1[] = { |
| 2384 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2385 | "Connection: keep-alive\r\n" |
| 2386 | "Content-Length: 22\r\n\r\n" |
| 2387 | "This server is borked." |
| 2388 | "Bonus data!"), |
| 2389 | }; |
| 2390 | |
| 2391 | MockWrite data_writes2[] = { |
| 2392 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2393 | "Host: www.borked.com\r\n" |
| 2394 | "Connection: keep-alive\r\n\r\n"), |
| 2395 | }; |
| 2396 | |
| 2397 | MockRead data_reads2[] = { |
| 2398 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2399 | "Content-Length: 3\r\n\r\n" |
| 2400 | "foo"), |
| 2401 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2402 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2403 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2404 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2405 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2406 | |
| 2407 | TestCompletionCallback callback; |
| 2408 | HttpRequestInfo request1; |
| 2409 | request1.method = "GET"; |
| 2410 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2411 | request1.traffic_annotation = |
| 2412 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2413 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2414 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2415 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2416 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2417 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2418 | |
| 2419 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2420 | ASSERT_TRUE(response1); |
| 2421 | ASSERT_TRUE(response1->headers); |
| 2422 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2423 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2424 | |
| 2425 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2426 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2427 | EXPECT_EQ("This server is borked.", response_data1); |
| 2428 | // Deleting the transaction attempts to release the socket back into the |
| 2429 | // socket pool. |
| 2430 | trans1.reset(); |
| 2431 | |
| 2432 | HttpRequestInfo request2; |
| 2433 | request2.method = "GET"; |
| 2434 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2435 | request2.traffic_annotation = |
| 2436 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2437 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2438 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2439 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2440 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2441 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2442 | |
| 2443 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2444 | ASSERT_TRUE(response2); |
| 2445 | ASSERT_TRUE(response2->headers); |
| 2446 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2447 | |
| 2448 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2449 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2450 | EXPECT_EQ("foo", response_data2); |
| 2451 | } |
| 2452 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2453 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2454 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2455 | MockWrite data_writes1[] = { |
| 2456 | MockWrite("GET / HTTP/1.1\r\n" |
| 2457 | "Host: www.borked.com\r\n" |
| 2458 | "Connection: keep-alive\r\n\r\n"), |
| 2459 | }; |
| 2460 | |
| 2461 | MockRead data_reads1[] = { |
| 2462 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2463 | "Connection: keep-alive\r\n" |
| 2464 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2465 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2466 | MockRead("0\r\n\r\nBonus data!"), |
| 2467 | }; |
| 2468 | |
| 2469 | MockWrite data_writes2[] = { |
| 2470 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2471 | "Host: www.borked.com\r\n" |
| 2472 | "Connection: keep-alive\r\n\r\n"), |
| 2473 | }; |
| 2474 | |
| 2475 | MockRead data_reads2[] = { |
| 2476 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2477 | "Content-Length: 3\r\n\r\n" |
| 2478 | "foo"), |
| 2479 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2480 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2481 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2482 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2483 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2484 | |
| 2485 | TestCompletionCallback callback; |
| 2486 | HttpRequestInfo request1; |
| 2487 | request1.method = "GET"; |
| 2488 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2489 | request1.traffic_annotation = |
| 2490 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2491 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2492 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2493 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2494 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2495 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2496 | |
| 2497 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2498 | ASSERT_TRUE(response1); |
| 2499 | ASSERT_TRUE(response1->headers); |
| 2500 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2501 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2502 | |
| 2503 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2504 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2505 | EXPECT_EQ("This server is borked.", response_data1); |
| 2506 | // Deleting the transaction attempts to release the socket back into the |
| 2507 | // socket pool. |
| 2508 | trans1.reset(); |
| 2509 | |
| 2510 | HttpRequestInfo request2; |
| 2511 | request2.method = "GET"; |
| 2512 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2513 | request2.traffic_annotation = |
| 2514 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2515 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2516 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2517 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2518 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2519 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2520 | |
| 2521 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2522 | ASSERT_TRUE(response2); |
| 2523 | ASSERT_TRUE(response2->headers); |
| 2524 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2525 | |
| 2526 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2527 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2528 | EXPECT_EQ("foo", response_data2); |
| 2529 | } |
| 2530 | |
| 2531 | // This is a little different from the others - it tests the case that the |
| 2532 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2533 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2534 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2535 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2536 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2537 | MockWrite data_writes1[] = { |
| 2538 | MockWrite("GET / HTTP/1.1\r\n" |
| 2539 | "Host: www.borked.com\r\n" |
| 2540 | "Connection: keep-alive\r\n\r\n"), |
| 2541 | }; |
| 2542 | |
| 2543 | MockRead data_reads1[] = { |
| 2544 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2545 | "Connection: keep-alive\r\n" |
| 2546 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2547 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2548 | MockRead("0\r\n\r\nBonus data!"), |
| 2549 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2550 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2551 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2552 | |
| 2553 | TestCompletionCallback callback; |
| 2554 | HttpRequestInfo request1; |
| 2555 | request1.method = "GET"; |
| 2556 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2557 | request1.traffic_annotation = |
| 2558 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2559 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2560 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2561 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2562 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2563 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2564 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2565 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2566 | ASSERT_TRUE(response1); |
| 2567 | ASSERT_TRUE(response1->headers); |
| 2568 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2569 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2570 | |
| 2571 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2572 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2573 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2574 | |
| 2575 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2576 | // socket can't be reused, rather than returning it to the socket pool. |
| 2577 | base::RunLoop().RunUntilIdle(); |
| 2578 | |
| 2579 | // There should be no idle sockets in the pool. |
| 2580 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2581 | } |
| 2582 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2583 | // Test the request-challenge-retry sequence for basic auth. |
| 2584 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2585 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2586 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2587 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2588 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2589 | request.traffic_annotation = |
| 2590 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2591 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2592 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2593 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2594 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2595 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2596 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2597 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2598 | MockWrite( |
| 2599 | "GET / HTTP/1.1\r\n" |
| 2600 | "Host: www.example.org\r\n" |
| 2601 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2602 | }; |
| 2603 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2604 | MockRead data_reads1[] = { |
| 2605 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2606 | // Give a couple authenticate options (only the middle one is actually |
| 2607 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2608 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2609 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2610 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2611 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2612 | // Large content-length -- won't matter, as connection will be reset. |
| 2613 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2614 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2615 | }; |
| 2616 | |
| 2617 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2618 | // be issuing -- the final header line contains the credentials. |
| 2619 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2620 | MockWrite( |
| 2621 | "GET / HTTP/1.1\r\n" |
| 2622 | "Host: www.example.org\r\n" |
| 2623 | "Connection: keep-alive\r\n" |
| 2624 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2625 | }; |
| 2626 | |
| 2627 | // Lastly, the server responds with the actual content. |
| 2628 | MockRead data_reads2[] = { |
| 2629 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2630 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2631 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2632 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2633 | }; |
| 2634 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2635 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2636 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2637 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2638 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2639 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2640 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2641 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2642 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2643 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2644 | |
| 2645 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2646 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2647 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2648 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2649 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2650 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2651 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2652 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2653 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2654 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2655 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2656 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2657 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2658 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2659 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2660 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2661 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2662 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2663 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2664 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2665 | |
| 2666 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2667 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2668 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2669 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2670 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2671 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2672 | // The load timing after restart should have a new socket ID, and times after |
| 2673 | // those of the first load timing. |
| 2674 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2675 | load_timing_info2.connect_timing.connect_start); |
| 2676 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2677 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2678 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2679 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2680 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2681 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2682 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2683 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2684 | ASSERT_TRUE(response); |
| 2685 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2686 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2687 | } |
| 2688 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2689 | // Test the request-challenge-retry sequence for basic auth. |
| 2690 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2691 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2692 | HttpRequestInfo request; |
| 2693 | request.method = "GET"; |
| 2694 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2695 | request.traffic_annotation = |
| 2696 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2697 | |
| 2698 | TestNetLog log; |
| 2699 | MockHostResolver* resolver = new MockHostResolver(); |
| 2700 | session_deps_.net_log = &log; |
| 2701 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2702 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2703 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2704 | |
| 2705 | resolver->rules()->ClearRules(); |
| 2706 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2707 | |
| 2708 | MockWrite data_writes1[] = { |
| 2709 | MockWrite("GET / HTTP/1.1\r\n" |
| 2710 | "Host: www.example.org\r\n" |
| 2711 | "Connection: keep-alive\r\n\r\n"), |
| 2712 | }; |
| 2713 | |
| 2714 | MockRead data_reads1[] = { |
| 2715 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2716 | // Give a couple authenticate options (only the middle one is actually |
| 2717 | // supported). |
| 2718 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2719 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2720 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2721 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2722 | // Large content-length -- won't matter, as connection will be reset. |
| 2723 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2724 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2725 | }; |
| 2726 | |
| 2727 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2728 | // be issuing -- the final header line contains the credentials. |
| 2729 | MockWrite data_writes2[] = { |
| 2730 | MockWrite("GET / HTTP/1.1\r\n" |
| 2731 | "Host: www.example.org\r\n" |
| 2732 | "Connection: keep-alive\r\n" |
| 2733 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2734 | }; |
| 2735 | |
| 2736 | // Lastly, the server responds with the actual content. |
| 2737 | MockRead data_reads2[] = { |
| 2738 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2739 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2740 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2741 | }; |
| 2742 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2743 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2744 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2745 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2746 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2747 | |
| 2748 | TestCompletionCallback callback1; |
| 2749 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2750 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2751 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2752 | |
| 2753 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2754 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2755 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2756 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2757 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2758 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2759 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2760 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2761 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2762 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2763 | ASSERT_TRUE(response); |
| 2764 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2765 | |
| 2766 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2767 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2768 | ASSERT_FALSE(endpoint.address().empty()); |
| 2769 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2770 | |
| 2771 | resolver->rules()->ClearRules(); |
| 2772 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2773 | |
| 2774 | TestCompletionCallback callback2; |
| 2775 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2776 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2777 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2778 | |
| 2779 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2780 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2781 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2782 | // The load timing after restart should have a new socket ID, and times after |
| 2783 | // those of the first load timing. |
| 2784 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2785 | load_timing_info2.connect_timing.connect_start); |
| 2786 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2787 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2788 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2789 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2790 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2791 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2792 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2793 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2794 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2795 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2796 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2797 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2798 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2799 | ASSERT_FALSE(endpoint.address().empty()); |
| 2800 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2801 | } |
| 2802 | |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2803 | // Test that, if the server requests auth indefinitely, HttpNetworkTransaction |
| 2804 | // will eventually give up. |
| 2805 | TEST_F(HttpNetworkTransactionTest, BasicAuthForever) { |
| 2806 | HttpRequestInfo request; |
| 2807 | request.method = "GET"; |
| 2808 | request.url = GURL("http://www.example.org/"); |
| 2809 | request.traffic_annotation = |
| 2810 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2811 | |
| 2812 | TestNetLog log; |
| 2813 | session_deps_.net_log = &log; |
| 2814 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2815 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 2816 | |
| 2817 | MockWrite data_writes[] = { |
| 2818 | MockWrite("GET / HTTP/1.1\r\n" |
| 2819 | "Host: www.example.org\r\n" |
| 2820 | "Connection: keep-alive\r\n\r\n"), |
| 2821 | }; |
| 2822 | |
| 2823 | MockRead data_reads[] = { |
| 2824 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2825 | // Give a couple authenticate options (only the middle one is actually |
| 2826 | // supported). |
| 2827 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2828 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2829 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2830 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2831 | // Large content-length -- won't matter, as connection will be reset. |
| 2832 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2833 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2834 | }; |
| 2835 | |
| 2836 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2837 | // be issuing -- the final header line contains the credentials. |
| 2838 | MockWrite data_writes_restart[] = { |
| 2839 | MockWrite("GET / HTTP/1.1\r\n" |
| 2840 | "Host: www.example.org\r\n" |
| 2841 | "Connection: keep-alive\r\n" |
| 2842 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2843 | }; |
| 2844 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2845 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2846 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2847 | |
| 2848 | TestCompletionCallback callback; |
| 2849 | int rv = callback.GetResult( |
| 2850 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 2851 | |
| 2852 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_restarts; |
| 2853 | for (int i = 0; i < 32; i++) { |
| 2854 | // Check the previous response was a 401. |
| 2855 | EXPECT_THAT(rv, IsOk()); |
| 2856 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 2857 | ASSERT_TRUE(response); |
| 2858 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2859 | |
| 2860 | data_restarts.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2861 | data_reads, data_writes_restart)); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2862 | session_deps_.socket_factory->AddSocketDataProvider( |
| 2863 | data_restarts.back().get()); |
| 2864 | rv = callback.GetResult(trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2865 | callback.callback())); |
| 2866 | } |
| 2867 | |
| 2868 | // After too many tries, the transaction should have given up. |
| 2869 | EXPECT_THAT(rv, IsError(ERR_TOO_MANY_RETRIES)); |
| 2870 | } |
| 2871 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2872 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2873 | HttpRequestInfo request; |
| 2874 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2875 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2876 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2877 | request.traffic_annotation = |
| 2878 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2879 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2880 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2881 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2882 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2883 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2884 | MockWrite( |
| 2885 | "GET / HTTP/1.1\r\n" |
| 2886 | "Host: www.example.org\r\n" |
| 2887 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2888 | }; |
| 2889 | |
| 2890 | MockRead data_reads[] = { |
| 2891 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2892 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2893 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2894 | // Large content-length -- won't matter, as connection will be reset. |
| 2895 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2896 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2897 | }; |
| 2898 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2899 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2900 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2901 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2902 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2903 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2904 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2905 | |
| 2906 | rv = callback.WaitForResult(); |
| 2907 | EXPECT_EQ(0, rv); |
| 2908 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2909 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2910 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2911 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2912 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2913 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2914 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2915 | ASSERT_TRUE(response); |
| 2916 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2917 | } |
| 2918 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2919 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2920 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2921 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2922 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2923 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2924 | // reused. See http://crbug.com/544255. |
| 2925 | for (int i = 0; i < 2; ++i) { |
| 2926 | HttpRequestInfo request; |
| 2927 | request.method = "GET"; |
| 2928 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2929 | request.traffic_annotation = |
| 2930 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2931 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2932 | TestNetLog log; |
| 2933 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2934 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2935 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2936 | MockWrite data_writes[] = { |
| 2937 | MockWrite(ASYNC, 0, |
| 2938 | "GET / HTTP/1.1\r\n" |
| 2939 | "Host: www.example.org\r\n" |
| 2940 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2941 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2942 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2943 | // be issuing -- the final header line contains the credentials. |
| 2944 | MockWrite(ASYNC, 6, |
| 2945 | "GET / HTTP/1.1\r\n" |
| 2946 | "Host: www.example.org\r\n" |
| 2947 | "Connection: keep-alive\r\n" |
| 2948 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2949 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2950 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2951 | MockRead data_reads[] = { |
| 2952 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2953 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2954 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2955 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2956 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2957 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2958 | // Lastly, the server responds with the actual content. |
| 2959 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2960 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2961 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2962 | MockRead(ASYNC, 10, "Hello"), |
| 2963 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2964 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2965 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2966 | data.set_busy_before_sync_reads(true); |
| 2967 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2968 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2969 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2970 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2971 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2972 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2973 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2974 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2975 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2976 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2977 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2978 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2979 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2980 | ASSERT_TRUE(response); |
| 2981 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2982 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2983 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2984 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2985 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2986 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2987 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2988 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2989 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2990 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2991 | TestLoadTimingReused(load_timing_info2); |
| 2992 | // The load timing after restart should have the same socket ID, and times |
| 2993 | // those of the first load timing. |
| 2994 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2995 | load_timing_info2.send_start); |
| 2996 | 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] | 2997 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2998 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2999 | ASSERT_TRUE(response); |
| 3000 | EXPECT_FALSE(response->auth_challenge); |
| 3001 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3002 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3003 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3004 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3005 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3006 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3007 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3008 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3009 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3010 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3011 | } |
| 3012 | |
| 3013 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3014 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3015 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3016 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3017 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3018 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3019 | request.traffic_annotation = |
| 3020 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3021 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3022 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3023 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3024 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3025 | MockWrite("GET / HTTP/1.1\r\n" |
| 3026 | "Host: www.example.org\r\n" |
| 3027 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3028 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3029 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3030 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3031 | MockWrite("GET / HTTP/1.1\r\n" |
| 3032 | "Host: www.example.org\r\n" |
| 3033 | "Connection: keep-alive\r\n" |
| 3034 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3035 | }; |
| 3036 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3037 | MockRead data_reads1[] = { |
| 3038 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3039 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3040 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3041 | |
| 3042 | // Lastly, the server responds with the actual content. |
| 3043 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3044 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3045 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3046 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3047 | }; |
| 3048 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3049 | // An incorrect reconnect would cause this to be read. |
| 3050 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3051 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3052 | }; |
| 3053 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3054 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3055 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3056 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3057 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3058 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3059 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3060 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3061 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3062 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3063 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3064 | |
| 3065 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3066 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3067 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3068 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3069 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3070 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3071 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3072 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3073 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3074 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3075 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3076 | |
| 3077 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3078 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3079 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3080 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3081 | ASSERT_TRUE(response); |
| 3082 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3083 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3084 | } |
| 3085 | |
| 3086 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3087 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3088 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3089 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3090 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3091 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3092 | request.traffic_annotation = |
| 3093 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3094 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3095 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3096 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3097 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3098 | MockWrite("GET / HTTP/1.1\r\n" |
| 3099 | "Host: www.example.org\r\n" |
| 3100 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3101 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3102 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3103 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3104 | MockWrite("GET / HTTP/1.1\r\n" |
| 3105 | "Host: www.example.org\r\n" |
| 3106 | "Connection: keep-alive\r\n" |
| 3107 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3108 | }; |
| 3109 | |
| 3110 | // Respond with 5 kb of response body. |
| 3111 | std::string large_body_string("Unauthorized"); |
| 3112 | large_body_string.append(5 * 1024, ' '); |
| 3113 | large_body_string.append("\r\n"); |
| 3114 | |
| 3115 | MockRead data_reads1[] = { |
| 3116 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3117 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3118 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3119 | // 5134 = 12 + 5 * 1024 + 2 |
| 3120 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3121 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3122 | |
| 3123 | // Lastly, the server responds with the actual content. |
| 3124 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3125 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3126 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3127 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3128 | }; |
| 3129 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3130 | // An incorrect reconnect would cause this to be read. |
| 3131 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3132 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3133 | }; |
| 3134 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3135 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3136 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3137 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3138 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3139 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3140 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3141 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3142 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3143 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3144 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3145 | |
| 3146 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3147 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3148 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3149 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3150 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3151 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3152 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3153 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3154 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3155 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3156 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3157 | |
| 3158 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3159 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3160 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3161 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3162 | ASSERT_TRUE(response); |
| 3163 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3164 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3165 | } |
| 3166 | |
| 3167 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3168 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3169 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3170 | HttpRequestInfo request; |
| 3171 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3172 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3173 | request.traffic_annotation = |
| 3174 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3175 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3176 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3177 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3178 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3179 | MockWrite( |
| 3180 | "GET / HTTP/1.1\r\n" |
| 3181 | "Host: www.example.org\r\n" |
| 3182 | "Connection: keep-alive\r\n\r\n"), |
| 3183 | // This simulates the seemingly successful write to a closed connection |
| 3184 | // if the bug is not fixed. |
| 3185 | MockWrite( |
| 3186 | "GET / HTTP/1.1\r\n" |
| 3187 | "Host: www.example.org\r\n" |
| 3188 | "Connection: keep-alive\r\n" |
| 3189 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3190 | }; |
| 3191 | |
| 3192 | MockRead data_reads1[] = { |
| 3193 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3194 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3195 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3196 | MockRead("Content-Length: 14\r\n\r\n"), |
| 3197 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3198 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3199 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3200 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3201 | }; |
| 3202 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3203 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3204 | // be issuing -- the final header line contains the credentials. |
| 3205 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3206 | MockWrite( |
| 3207 | "GET / HTTP/1.1\r\n" |
| 3208 | "Host: www.example.org\r\n" |
| 3209 | "Connection: keep-alive\r\n" |
| 3210 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3211 | }; |
| 3212 | |
| 3213 | // Lastly, the server responds with the actual content. |
| 3214 | MockRead data_reads2[] = { |
| 3215 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3216 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3217 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3218 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3219 | }; |
| 3220 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3221 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3222 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3223 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3224 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3225 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3226 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3227 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3228 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3229 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3230 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3231 | |
| 3232 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3233 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3234 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3235 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3236 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3237 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3238 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3239 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3240 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3241 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3242 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3243 | |
| 3244 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3245 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3246 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3247 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3248 | ASSERT_TRUE(response); |
| 3249 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3250 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3251 | } |
| 3252 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3253 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3254 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3255 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3256 | HttpRequestInfo request; |
| 3257 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3258 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3259 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3260 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3261 | request.traffic_annotation = |
| 3262 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3263 | |
| 3264 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3265 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3266 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3267 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3268 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3269 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3270 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3271 | |
| 3272 | // Since we have proxy, should try to establish tunnel. |
| 3273 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3274 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3275 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3276 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3277 | }; |
| 3278 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3279 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3280 | // connection. |
| 3281 | MockRead data_reads1[] = { |
| 3282 | // No credentials. |
| 3283 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3284 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3285 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3286 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3287 | // Since the first connection couldn't be reused, need to establish another |
| 3288 | // once given credentials. |
| 3289 | MockWrite data_writes2[] = { |
| 3290 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3291 | // be issuing -- the final header line contains the credentials. |
| 3292 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3293 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3294 | "Proxy-Connection: keep-alive\r\n" |
| 3295 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3296 | |
| 3297 | MockWrite("GET / HTTP/1.1\r\n" |
| 3298 | "Host: www.example.org\r\n" |
| 3299 | "Connection: keep-alive\r\n\r\n"), |
| 3300 | }; |
| 3301 | |
| 3302 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3303 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3304 | |
| 3305 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3306 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3307 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3308 | MockRead(SYNCHRONOUS, "hello"), |
| 3309 | }; |
| 3310 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3311 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3312 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3313 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3314 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3315 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3316 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3317 | |
| 3318 | TestCompletionCallback callback1; |
| 3319 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3320 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3321 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3322 | |
| 3323 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3324 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3325 | |
| 3326 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3327 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3328 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3329 | log.GetEntries(&entries); |
| 3330 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3331 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3332 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3333 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3334 | entries, pos, |
| 3335 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3336 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3337 | |
| 3338 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3339 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3340 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3341 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3342 | EXPECT_EQ(407, response->headers->response_code()); |
| 3343 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3344 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3345 | |
| 3346 | LoadTimingInfo load_timing_info; |
| 3347 | // CONNECT requests and responses are handled at the connect job level, so |
| 3348 | // the transaction does not yet have a connection. |
| 3349 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3350 | |
| 3351 | TestCompletionCallback callback2; |
| 3352 | |
| 3353 | rv = |
| 3354 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3355 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3356 | |
| 3357 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3358 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3359 | |
| 3360 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3361 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3362 | |
| 3363 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3364 | EXPECT_EQ(200, response->headers->response_code()); |
| 3365 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3366 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3367 | |
| 3368 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3369 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3370 | |
| 3371 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3372 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3373 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3374 | |
| 3375 | trans.reset(); |
| 3376 | session->CloseAllConnections(); |
| 3377 | } |
| 3378 | |
| 3379 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3380 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3381 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3382 | HttpRequestInfo request; |
| 3383 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3384 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3385 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3386 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3387 | request.traffic_annotation = |
| 3388 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3389 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3390 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3391 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3392 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3393 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3394 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3395 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3396 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3397 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3398 | // Since we have proxy, should try to establish tunnel. |
| 3399 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3400 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3401 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3402 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3403 | }; |
| 3404 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3405 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3406 | // connection. |
| 3407 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3408 | // No credentials. |
| 3409 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3410 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3411 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3412 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3413 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3414 | MockWrite data_writes2[] = { |
| 3415 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3416 | // be issuing -- the final header line contains the credentials. |
| 3417 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3418 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3419 | "Proxy-Connection: keep-alive\r\n" |
| 3420 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3421 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3422 | MockWrite("GET / HTTP/1.1\r\n" |
| 3423 | "Host: www.example.org\r\n" |
| 3424 | "Connection: keep-alive\r\n\r\n"), |
| 3425 | }; |
| 3426 | |
| 3427 | MockRead data_reads2[] = { |
| 3428 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3429 | |
| 3430 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3431 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3432 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3433 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3434 | }; |
| 3435 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3436 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3437 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3438 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3439 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3440 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3441 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3442 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3443 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3444 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3445 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3446 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3447 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3448 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3449 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3450 | |
| 3451 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3452 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3453 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3454 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3455 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3456 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3457 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3458 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3459 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3460 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3461 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3462 | |
| 3463 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3464 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3465 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3466 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3467 | EXPECT_EQ(407, response->headers->response_code()); |
| 3468 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3469 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3470 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3471 | LoadTimingInfo load_timing_info; |
| 3472 | // CONNECT requests and responses are handled at the connect job level, so |
| 3473 | // the transaction does not yet have a connection. |
| 3474 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3475 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3476 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3477 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3478 | rv = trans->RestartWithAuth( |
| 3479 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3480 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3481 | |
| 3482 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3483 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3484 | |
| 3485 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3486 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3487 | |
| 3488 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3489 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3490 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3491 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3492 | |
| 3493 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3494 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3495 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3496 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3497 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3498 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3499 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3500 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3501 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3502 | } |
| 3503 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3504 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3505 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3506 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3507 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3508 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3509 | // reused. See http://crbug.com/544255. |
| 3510 | for (int i = 0; i < 2; ++i) { |
| 3511 | HttpRequestInfo request; |
| 3512 | request.method = "GET"; |
| 3513 | request.url = GURL("https://www.example.org/"); |
| 3514 | // Ensure that proxy authentication is attempted even |
| 3515 | // when the no authentication data flag is set. |
| 3516 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3517 | request.traffic_annotation = |
| 3518 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3519 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3520 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3521 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3522 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3523 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3524 | BoundTestNetLog log; |
| 3525 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3526 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3527 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3528 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3529 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3530 | // Since we have proxy, should try to establish tunnel. |
| 3531 | MockWrite data_writes1[] = { |
| 3532 | MockWrite(ASYNC, 0, |
| 3533 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3534 | "Host: www.example.org:443\r\n" |
| 3535 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3536 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3537 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3538 | // be issuing -- the final header line contains the credentials. |
| 3539 | MockWrite(ASYNC, 3, |
| 3540 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3541 | "Host: www.example.org:443\r\n" |
| 3542 | "Proxy-Connection: keep-alive\r\n" |
| 3543 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3544 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3545 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3546 | // The proxy responds to the connect with a 407, using a persistent |
| 3547 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3548 | MockRead data_reads1[] = { |
| 3549 | // No credentials. |
| 3550 | MockRead(ASYNC, 1, |
| 3551 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3552 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3553 | "Proxy-Connection: keep-alive\r\n" |
| 3554 | "Content-Length: 10\r\n\r\n"), |
| 3555 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3556 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3557 | // Wrong credentials (wrong password). |
| 3558 | MockRead(ASYNC, 4, |
| 3559 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3560 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3561 | "Proxy-Connection: keep-alive\r\n" |
| 3562 | "Content-Length: 10\r\n\r\n"), |
| 3563 | // No response body because the test stops reading here. |
| 3564 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3565 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3566 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3567 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3568 | data1.set_busy_before_sync_reads(true); |
| 3569 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3570 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3571 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3572 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3573 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3574 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3575 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3576 | TestNetLogEntry::List entries; |
| 3577 | log.GetEntries(&entries); |
| 3578 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3579 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3580 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3581 | ExpectLogContainsSomewhere( |
| 3582 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3583 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3584 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3585 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3586 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3587 | ASSERT_TRUE(response); |
| 3588 | ASSERT_TRUE(response->headers); |
| 3589 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3590 | EXPECT_EQ(407, response->headers->response_code()); |
| 3591 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3592 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3593 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3594 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3595 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3596 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3597 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3598 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3599 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3600 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3601 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3602 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3603 | ASSERT_TRUE(response); |
| 3604 | ASSERT_TRUE(response->headers); |
| 3605 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3606 | EXPECT_EQ(407, response->headers->response_code()); |
| 3607 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3608 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3609 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3610 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3611 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3612 | // out of scope. |
| 3613 | session->CloseAllConnections(); |
| 3614 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3615 | } |
| 3616 | |
| 3617 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3618 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3619 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3620 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3621 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3622 | // reused. See http://crbug.com/544255. |
| 3623 | for (int i = 0; i < 2; ++i) { |
| 3624 | HttpRequestInfo request; |
| 3625 | request.method = "GET"; |
| 3626 | request.url = GURL("https://www.example.org/"); |
| 3627 | // Ensure that proxy authentication is attempted even |
| 3628 | // when the no authentication data flag is set. |
| 3629 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3630 | request.traffic_annotation = |
| 3631 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3632 | |
| 3633 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3634 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3635 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3636 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3637 | BoundTestNetLog log; |
| 3638 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3639 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3640 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3641 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3642 | |
| 3643 | // Since we have proxy, should try to establish tunnel. |
| 3644 | MockWrite data_writes1[] = { |
| 3645 | MockWrite(ASYNC, 0, |
| 3646 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3647 | "Host: www.example.org:443\r\n" |
| 3648 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3649 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3650 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3651 | // be issuing -- the final header line contains the credentials. |
| 3652 | MockWrite(ASYNC, 3, |
| 3653 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3654 | "Host: www.example.org:443\r\n" |
| 3655 | "Proxy-Connection: keep-alive\r\n" |
| 3656 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3657 | }; |
| 3658 | |
| 3659 | // The proxy responds to the connect with a 407, using a persistent |
| 3660 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3661 | MockRead data_reads1[] = { |
| 3662 | // No credentials. |
| 3663 | MockRead(ASYNC, 1, |
| 3664 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3665 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3666 | "Content-Length: 10\r\n\r\n"), |
| 3667 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3668 | |
| 3669 | // Wrong credentials (wrong password). |
| 3670 | MockRead(ASYNC, 4, |
| 3671 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3672 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3673 | "Content-Length: 10\r\n\r\n"), |
| 3674 | // No response body because the test stops reading here. |
| 3675 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3676 | }; |
| 3677 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3678 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3679 | data1.set_busy_before_sync_reads(true); |
| 3680 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3681 | |
| 3682 | TestCompletionCallback callback1; |
| 3683 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3684 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3685 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3686 | |
| 3687 | TestNetLogEntry::List entries; |
| 3688 | log.GetEntries(&entries); |
| 3689 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3690 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3691 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3692 | ExpectLogContainsSomewhere( |
| 3693 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3694 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3695 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3696 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3697 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3698 | ASSERT_TRUE(response); |
| 3699 | ASSERT_TRUE(response->headers); |
| 3700 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3701 | EXPECT_EQ(407, response->headers->response_code()); |
| 3702 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3703 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3704 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3705 | |
| 3706 | TestCompletionCallback callback2; |
| 3707 | |
| 3708 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3709 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3710 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3711 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3712 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3713 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3714 | ASSERT_TRUE(response); |
| 3715 | ASSERT_TRUE(response->headers); |
| 3716 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3717 | EXPECT_EQ(407, response->headers->response_code()); |
| 3718 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3719 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3720 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3721 | |
| 3722 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3723 | // out of scope. |
| 3724 | session->CloseAllConnections(); |
| 3725 | } |
| 3726 | } |
| 3727 | |
| 3728 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3729 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3730 | // the case the server sends extra data on the original socket, so it can't be |
| 3731 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3732 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3733 | HttpRequestInfo request; |
| 3734 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3735 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3736 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3737 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3738 | request.traffic_annotation = |
| 3739 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3740 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3741 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3742 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3743 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3744 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3745 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3746 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3747 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3748 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3749 | // Since we have proxy, should try to establish tunnel. |
| 3750 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3751 | MockWrite(ASYNC, 0, |
| 3752 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3753 | "Host: www.example.org:443\r\n" |
| 3754 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3755 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3756 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3757 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3758 | // extra data, so the socket cannot be reused. |
| 3759 | MockRead data_reads1[] = { |
| 3760 | // No credentials. |
| 3761 | MockRead(ASYNC, 1, |
| 3762 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3763 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3764 | "Content-Length: 10\r\n\r\n"), |
| 3765 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3766 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3767 | }; |
| 3768 | |
| 3769 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3770 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3771 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3772 | MockWrite(ASYNC, 0, |
| 3773 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3774 | "Host: www.example.org:443\r\n" |
| 3775 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3776 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3777 | |
| 3778 | MockWrite(ASYNC, 2, |
| 3779 | "GET / HTTP/1.1\r\n" |
| 3780 | "Host: www.example.org\r\n" |
| 3781 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3782 | }; |
| 3783 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3784 | MockRead data_reads2[] = { |
| 3785 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3786 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3787 | MockRead(ASYNC, 3, |
| 3788 | "HTTP/1.1 200 OK\r\n" |
| 3789 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3790 | "Content-Length: 5\r\n\r\n"), |
| 3791 | // No response body because the test stops reading here. |
| 3792 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3793 | }; |
| 3794 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3795 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3796 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3797 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3798 | SequencedSocketData data2(data_reads2, data_writes2); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3799 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3800 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3801 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3802 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3803 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3804 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3805 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3806 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3807 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3808 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3809 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3810 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3811 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3812 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3813 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3814 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3815 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3816 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3817 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3818 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3819 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3820 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3821 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3822 | ASSERT_TRUE(response); |
| 3823 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3824 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3825 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3826 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3827 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3828 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3829 | LoadTimingInfo load_timing_info; |
| 3830 | // CONNECT requests and responses are handled at the connect job level, so |
| 3831 | // the transaction does not yet have a connection. |
| 3832 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3833 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3834 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3835 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3836 | rv = |
| 3837 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3838 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3839 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3840 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3841 | EXPECT_EQ(200, response->headers->response_code()); |
| 3842 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3843 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3844 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3845 | // The password prompt info should not be set. |
| 3846 | EXPECT_FALSE(response->auth_challenge); |
| 3847 | |
| 3848 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3849 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3850 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3851 | |
| 3852 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3853 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3854 | } |
| 3855 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3856 | // Test the case a proxy closes a socket while the challenge body is being |
| 3857 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3858 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3859 | HttpRequestInfo request; |
| 3860 | request.method = "GET"; |
| 3861 | request.url = GURL("https://www.example.org/"); |
| 3862 | // Ensure that proxy authentication is attempted even |
| 3863 | // when the no authentication data flag is set. |
| 3864 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3865 | request.traffic_annotation = |
| 3866 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3867 | |
| 3868 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3869 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3870 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3871 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3872 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3873 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3874 | |
| 3875 | // Since we have proxy, should try to establish tunnel. |
| 3876 | MockWrite data_writes1[] = { |
| 3877 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3878 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3879 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3880 | }; |
| 3881 | |
| 3882 | // The proxy responds to the connect with a 407, using a persistent |
| 3883 | // connection. |
| 3884 | MockRead data_reads1[] = { |
| 3885 | // No credentials. |
| 3886 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3887 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3888 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3889 | // Server hands up in the middle of the body. |
| 3890 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3891 | }; |
| 3892 | |
| 3893 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3894 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3895 | // be issuing -- the final header line contains the credentials. |
| 3896 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3897 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3898 | "Proxy-Connection: keep-alive\r\n" |
| 3899 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3900 | |
| 3901 | MockWrite("GET / HTTP/1.1\r\n" |
| 3902 | "Host: www.example.org\r\n" |
| 3903 | "Connection: keep-alive\r\n\r\n"), |
| 3904 | }; |
| 3905 | |
| 3906 | MockRead data_reads2[] = { |
| 3907 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3908 | |
| 3909 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3910 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3911 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3912 | MockRead(SYNCHRONOUS, "hello"), |
| 3913 | }; |
| 3914 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3915 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3916 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3917 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3918 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3919 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3920 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3921 | |
| 3922 | TestCompletionCallback callback; |
| 3923 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3924 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3925 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3926 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3927 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3928 | ASSERT_TRUE(response); |
| 3929 | ASSERT_TRUE(response->headers); |
| 3930 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3931 | EXPECT_EQ(407, response->headers->response_code()); |
| 3932 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3933 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3934 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3935 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3936 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3937 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3938 | ASSERT_TRUE(response); |
| 3939 | ASSERT_TRUE(response->headers); |
| 3940 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3941 | EXPECT_EQ(200, response->headers->response_code()); |
| 3942 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3943 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3944 | EXPECT_EQ("hello", body); |
| 3945 | } |
| 3946 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3947 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3948 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3949 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3950 | HttpRequestInfo request; |
| 3951 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3952 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3953 | request.traffic_annotation = |
| 3954 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3955 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3956 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3957 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3958 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3959 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3960 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3961 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3962 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3963 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3964 | // Since we have proxy, should try to establish tunnel. |
| 3965 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3966 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3967 | "Host: www.example.org:443\r\n" |
| 3968 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3969 | }; |
| 3970 | |
| 3971 | // The proxy responds to the connect with a 407. |
| 3972 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3973 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3974 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3975 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3976 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3977 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3978 | }; |
| 3979 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3980 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3981 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3982 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3983 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3984 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3985 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3986 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3987 | |
| 3988 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3989 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3990 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3991 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3992 | ASSERT_TRUE(response); |
| 3993 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3994 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3995 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3996 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3997 | |
| 3998 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3999 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4000 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 4001 | |
| 4002 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 4003 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4004 | } |
| 4005 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4006 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 4007 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4008 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4009 | HttpRequestInfo request; |
| 4010 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4011 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4012 | request.traffic_annotation = |
| 4013 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4014 | |
| 4015 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4016 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4017 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4018 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4019 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4020 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4021 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4022 | |
| 4023 | // Since we have proxy, should try to establish tunnel. |
| 4024 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4025 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4026 | "Host: www.example.org:443\r\n" |
| 4027 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4028 | }; |
| 4029 | |
| 4030 | // The proxy responds to the connect with a 407. |
| 4031 | MockRead data_reads[] = { |
| 4032 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4033 | MockRead("X-Foo: bar\r\n"), |
| 4034 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 4035 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4036 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4037 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4038 | }; |
| 4039 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4040 | StaticSocketDataProvider data(data_reads, data_writes); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4041 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4042 | |
| 4043 | TestCompletionCallback callback; |
| 4044 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4045 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4046 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4047 | |
| 4048 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4049 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4050 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4051 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4052 | ASSERT_TRUE(response); |
| 4053 | ASSERT_TRUE(response->headers); |
| 4054 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4055 | EXPECT_EQ(407, response->headers->response_code()); |
| 4056 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4057 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 4058 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 4059 | |
| 4060 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4061 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4062 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4063 | |
| 4064 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 4065 | session->CloseAllConnections(); |
| 4066 | } |
| 4067 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4068 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 4069 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4070 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4071 | HttpRequestInfo request; |
| 4072 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4073 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4074 | request.traffic_annotation = |
| 4075 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4076 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4077 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4078 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4079 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4080 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4081 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4082 | MockWrite( |
| 4083 | "GET / HTTP/1.1\r\n" |
| 4084 | "Host: www.example.org\r\n" |
| 4085 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4086 | }; |
| 4087 | |
| 4088 | MockRead data_reads1[] = { |
| 4089 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 4090 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4091 | // Large content-length -- won't matter, as connection will be reset. |
| 4092 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4093 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4094 | }; |
| 4095 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4096 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4097 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4098 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4099 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4100 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4101 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4102 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4103 | |
| 4104 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4105 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4106 | } |
| 4107 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4108 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 4109 | // through a non-authenticating proxy. The request should fail with |
| 4110 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 4111 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 4112 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 4113 | // response came from the proxy or the server, so it is treated as if the proxy |
| 4114 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4115 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4116 | HttpRequestInfo request; |
| 4117 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4118 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4119 | request.traffic_annotation = |
| 4120 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4121 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4122 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4123 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4124 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4125 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4126 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4127 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4128 | // Since we have proxy, should try to establish tunnel. |
| 4129 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4130 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4131 | "Host: www.example.org:443\r\n" |
| 4132 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4133 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4134 | MockWrite("GET / HTTP/1.1\r\n" |
| 4135 | "Host: www.example.org\r\n" |
| 4136 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4137 | }; |
| 4138 | |
| 4139 | MockRead data_reads1[] = { |
| 4140 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4141 | |
| 4142 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 4143 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4144 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4145 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4146 | }; |
| 4147 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4148 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4149 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4150 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4151 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4152 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4153 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4154 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4155 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4156 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4157 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4158 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4159 | |
| 4160 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4161 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 4162 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4163 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4164 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4165 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 4166 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4167 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4168 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4169 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 4170 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4171 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4172 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4173 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4174 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4175 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4176 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 4177 | HttpRequestInfo request; |
| 4178 | request.method = "GET"; |
| 4179 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4180 | request.traffic_annotation = |
| 4181 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4182 | |
| 4183 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4184 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4185 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4186 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4187 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4188 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4189 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4190 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4191 | mock_handler->set_allows_default_credentials(true); |
| 4192 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4193 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4194 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4195 | |
| 4196 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4197 | NetLog net_log; |
| 4198 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4199 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4200 | |
| 4201 | // Since we have proxy, should try to establish tunnel. |
| 4202 | MockWrite data_writes1[] = { |
| 4203 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4204 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4205 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4206 | }; |
| 4207 | |
| 4208 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4209 | // connection. |
| 4210 | MockRead data_reads1[] = { |
| 4211 | // No credentials. |
| 4212 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4213 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4214 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4215 | }; |
| 4216 | |
| 4217 | // Since the first connection couldn't be reused, need to establish another |
| 4218 | // once given credentials. |
| 4219 | MockWrite data_writes2[] = { |
| 4220 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4221 | // be issuing -- the final header line contains the credentials. |
| 4222 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4223 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4224 | "Proxy-Connection: keep-alive\r\n" |
| 4225 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4226 | |
| 4227 | MockWrite("GET / HTTP/1.1\r\n" |
| 4228 | "Host: www.example.org\r\n" |
| 4229 | "Connection: keep-alive\r\n\r\n"), |
| 4230 | }; |
| 4231 | |
| 4232 | MockRead data_reads2[] = { |
| 4233 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4234 | |
| 4235 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4236 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4237 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4238 | MockRead(SYNCHRONOUS, "hello"), |
| 4239 | }; |
| 4240 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4241 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4242 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4243 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4244 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4245 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4246 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4247 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4248 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4249 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4250 | |
| 4251 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4252 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4253 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4254 | |
| 4255 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4256 | ASSERT_TRUE(response); |
| 4257 | ASSERT_TRUE(response->headers); |
| 4258 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4259 | EXPECT_EQ(407, response->headers->response_code()); |
| 4260 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4261 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4262 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4263 | |
| 4264 | LoadTimingInfo load_timing_info; |
| 4265 | // CONNECT requests and responses are handled at the connect job level, so |
| 4266 | // the transaction does not yet have a connection. |
| 4267 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4268 | |
| 4269 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4270 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4271 | response = trans->GetResponseInfo(); |
| 4272 | ASSERT_TRUE(response); |
| 4273 | ASSERT_TRUE(response->headers); |
| 4274 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4275 | EXPECT_EQ(200, response->headers->response_code()); |
| 4276 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4277 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4278 | |
| 4279 | // The password prompt info should not be set. |
| 4280 | EXPECT_FALSE(response->auth_challenge); |
| 4281 | |
| 4282 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4283 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4284 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4285 | |
| 4286 | trans.reset(); |
| 4287 | session->CloseAllConnections(); |
| 4288 | } |
| 4289 | |
| 4290 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4291 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4292 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4293 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4294 | HttpRequestInfo request; |
| 4295 | request.method = "GET"; |
| 4296 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4297 | request.traffic_annotation = |
| 4298 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4299 | |
| 4300 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4301 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4302 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4303 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4304 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4305 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4306 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4307 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4308 | mock_handler->set_allows_default_credentials(true); |
| 4309 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4310 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4311 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4312 | |
| 4313 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4314 | NetLog net_log; |
| 4315 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4316 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4317 | |
| 4318 | // Should try to establish tunnel. |
| 4319 | MockWrite data_writes1[] = { |
| 4320 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4321 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4322 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4323 | |
| 4324 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4325 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4326 | "Proxy-Connection: keep-alive\r\n" |
| 4327 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4328 | }; |
| 4329 | |
| 4330 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4331 | // connection. |
| 4332 | MockRead data_reads1[] = { |
| 4333 | // No credentials. |
| 4334 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4335 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4336 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4337 | }; |
| 4338 | |
| 4339 | // Since the first connection was closed, need to establish another once given |
| 4340 | // credentials. |
| 4341 | MockWrite data_writes2[] = { |
| 4342 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4343 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4344 | "Proxy-Connection: keep-alive\r\n" |
| 4345 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4346 | |
| 4347 | MockWrite("GET / HTTP/1.1\r\n" |
| 4348 | "Host: www.example.org\r\n" |
| 4349 | "Connection: keep-alive\r\n\r\n"), |
| 4350 | }; |
| 4351 | |
| 4352 | MockRead data_reads2[] = { |
| 4353 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4354 | |
| 4355 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4356 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4357 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4358 | MockRead(SYNCHRONOUS, "hello"), |
| 4359 | }; |
| 4360 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4361 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4362 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4363 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4364 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4365 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4366 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4367 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4368 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4369 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4370 | |
| 4371 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4372 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4373 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4374 | |
| 4375 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4376 | ASSERT_TRUE(response); |
| 4377 | ASSERT_TRUE(response->headers); |
| 4378 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4379 | EXPECT_EQ(407, response->headers->response_code()); |
| 4380 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4381 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4382 | EXPECT_FALSE(response->auth_challenge); |
| 4383 | |
| 4384 | LoadTimingInfo load_timing_info; |
| 4385 | // CONNECT requests and responses are handled at the connect job level, so |
| 4386 | // the transaction does not yet have a connection. |
| 4387 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4388 | |
| 4389 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4390 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4391 | |
| 4392 | response = trans->GetResponseInfo(); |
| 4393 | ASSERT_TRUE(response); |
| 4394 | ASSERT_TRUE(response->headers); |
| 4395 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4396 | EXPECT_EQ(200, response->headers->response_code()); |
| 4397 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4398 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4399 | |
| 4400 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4401 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4402 | |
| 4403 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4404 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4405 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4406 | |
| 4407 | trans.reset(); |
| 4408 | session->CloseAllConnections(); |
| 4409 | } |
| 4410 | |
| 4411 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4412 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4413 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4414 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4415 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4416 | HttpRequestInfo request; |
| 4417 | request.method = "GET"; |
| 4418 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4419 | request.traffic_annotation = |
| 4420 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4421 | |
| 4422 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4423 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4424 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4425 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4426 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4427 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4428 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4429 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4430 | mock_handler->set_allows_default_credentials(true); |
| 4431 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4432 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4433 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4434 | |
| 4435 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4436 | NetLog net_log; |
| 4437 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4438 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4439 | |
| 4440 | // Should try to establish tunnel. |
| 4441 | MockWrite data_writes1[] = { |
| 4442 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4443 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4444 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4445 | |
| 4446 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4447 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4448 | "Proxy-Connection: keep-alive\r\n" |
| 4449 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4450 | }; |
| 4451 | |
| 4452 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4453 | // second request is sent. |
| 4454 | MockRead data_reads1[] = { |
| 4455 | // No credentials. |
| 4456 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4457 | MockRead("Content-Length: 0\r\n"), |
| 4458 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4459 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4460 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4461 | }; |
| 4462 | |
| 4463 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4464 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4465 | // request. |
| 4466 | MockWrite data_writes2[] = { |
| 4467 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4468 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4469 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4470 | }; |
| 4471 | |
| 4472 | // The proxy, having had more than enough of us, just hangs up. |
| 4473 | MockRead data_reads2[] = { |
| 4474 | // No credentials. |
| 4475 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4476 | }; |
| 4477 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4478 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4479 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4480 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4481 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4482 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4483 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4484 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4485 | |
| 4486 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4487 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4488 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4489 | |
| 4490 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4491 | ASSERT_TRUE(response); |
| 4492 | ASSERT_TRUE(response->headers); |
| 4493 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4494 | EXPECT_EQ(407, response->headers->response_code()); |
| 4495 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4496 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4497 | EXPECT_FALSE(response->auth_challenge); |
| 4498 | |
| 4499 | LoadTimingInfo load_timing_info; |
| 4500 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4501 | |
| 4502 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4503 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4504 | |
| 4505 | trans.reset(); |
| 4506 | session->CloseAllConnections(); |
| 4507 | } |
| 4508 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4509 | // This test exercises an odd edge case where the proxy closes the connection |
| 4510 | // after the authentication handshake is complete. Presumably this technique is |
| 4511 | // used in lieu of returning a 403 or 5xx status code when the authentication |
| 4512 | // succeeds, but the user is not authorized to connect to the destination |
| 4513 | // server. There's no standard for what a proxy should do to indicate a blocked |
| 4514 | // site. |
| 4515 | TEST_F(HttpNetworkTransactionTest, |
| 4516 | AuthAllowsDefaultCredentialsTunnelConnectionClosesBeforeBody) { |
| 4517 | HttpRequestInfo request; |
| 4518 | request.method = "GET"; |
| 4519 | request.url = GURL("https://www.example.org/"); |
| 4520 | request.traffic_annotation = |
| 4521 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4522 | |
| 4523 | // Configure against proxy server "myproxy:70". |
| 4524 | session_deps_.proxy_resolution_service = |
| 4525 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4526 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4527 | |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 4528 | // When TLS 1.3 is enabled, spurious connections are made as part of the SSL |
| 4529 | // version interference probes. |
| 4530 | // TODO(crbug.com/906668): Correctly handle version interference probes to |
| 4531 | // test TLS 1.3. |
| 4532 | SSLConfig config; |
| 4533 | config.version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
| 4534 | session_deps_.ssl_config_service = |
| 4535 | std::make_unique<TestSSLConfigService>(config); |
| 4536 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4537 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
| 4538 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4539 | |
| 4540 | // Create two mock AuthHandlers. This is because the transaction gets retried |
| 4541 | // after the first ERR_CONNECTION_CLOSED since it's ambiguous whether there |
| 4542 | // was a real network error. |
| 4543 | // |
| 4544 | // The handlers support both default and explicit credentials. The retry |
| 4545 | // mentioned above should be able to reuse the default identity. Thus there |
| 4546 | // should never be a need to prompt for explicit credentials. |
| 4547 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4548 | mock_handler->set_allows_default_credentials(true); |
| 4549 | mock_handler->set_allows_explicit_credentials(true); |
| 4550 | mock_handler->set_connection_based(true); |
| 4551 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4552 | HttpAuth::AUTH_PROXY); |
| 4553 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4554 | mock_handler->set_allows_default_credentials(true); |
| 4555 | mock_handler->set_allows_explicit_credentials(true); |
| 4556 | mock_handler->set_connection_based(true); |
| 4557 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4558 | HttpAuth::AUTH_PROXY); |
| 4559 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4560 | |
| 4561 | NetLog net_log; |
| 4562 | session_deps_.net_log = &net_log; |
| 4563 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4564 | |
| 4565 | // Data for both sockets. |
| 4566 | // |
| 4567 | // Writes are for the tunnel establishment attempts and the |
| 4568 | // authentication handshake. |
| 4569 | MockWrite data_writes1[] = { |
| 4570 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4571 | "Host: www.example.org:443\r\n" |
| 4572 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4573 | |
| 4574 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4575 | "Host: www.example.org:443\r\n" |
| 4576 | "Proxy-Connection: keep-alive\r\n" |
| 4577 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4578 | |
| 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" |
| 4582 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4583 | }; |
| 4584 | |
| 4585 | // The server side of the authentication handshake. Note that the response to |
| 4586 | // the final CONNECT request is ERR_CONNECTION_CLOSED. |
| 4587 | MockRead data_reads1[] = { |
| 4588 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4589 | MockRead("Content-Length: 0\r\n"), |
| 4590 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4591 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4592 | |
| 4593 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4594 | MockRead("Content-Length: 0\r\n"), |
| 4595 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4596 | MockRead("Proxy-Authenticate: Mock foo\r\n\r\n"), |
| 4597 | |
| 4598 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4599 | }; |
| 4600 | |
| 4601 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 4602 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4603 | |
| 4604 | // The second socket is for the reconnection attempt. Data is identical to the |
| 4605 | // first attempt. |
| 4606 | StaticSocketDataProvider data2(data_reads1, data_writes1); |
| 4607 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4608 | |
| 4609 | auto trans = |
| 4610 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4611 | |
| 4612 | TestCompletionCallback callback; |
| 4613 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4614 | |
| 4615 | // Two rounds per handshake. After one retry, the error is propagated up the |
| 4616 | // stack. |
| 4617 | for (int i = 0; i < 4; ++i) { |
| 4618 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4619 | |
| 4620 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4621 | ASSERT_TRUE(response); |
| 4622 | ASSERT_TRUE(response->headers); |
| 4623 | EXPECT_EQ(407, response->headers->response_code()); |
| 4624 | ASSERT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4625 | |
| 4626 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4627 | } |
| 4628 | |
| 4629 | // One shall be the number thou shalt retry, and the number of the retrying |
| 4630 | // shall be one. Two shalt thou not retry, neither retry thou zero, excepting |
| 4631 | // that thou then proceed to one. Three is right out. Once the number one, |
| 4632 | // being the first number, be reached, then lobbest thou thy |
| 4633 | // ERR_CONNECTION_CLOSED towards they network transaction, who shall snuff it. |
| 4634 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.GetResult(rv)); |
| 4635 | |
| 4636 | trans.reset(); |
| 4637 | session->CloseAllConnections(); |
| 4638 | } |
| 4639 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4640 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4641 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4642 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4643 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4644 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4645 | HttpRequestInfo request; |
| 4646 | request.method = "GET"; |
| 4647 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4648 | request.traffic_annotation = |
| 4649 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4650 | |
| 4651 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4652 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4653 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4654 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4655 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4656 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4657 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4658 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4659 | mock_handler->set_allows_default_credentials(true); |
| 4660 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4661 | HttpAuth::AUTH_PROXY); |
| 4662 | // Add another handler for the second challenge. It supports default |
| 4663 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4664 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4665 | mock_handler->set_allows_default_credentials(true); |
| 4666 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4667 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4668 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4669 | |
| 4670 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4671 | NetLog net_log; |
| 4672 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4673 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4674 | |
| 4675 | // Should try to establish tunnel. |
| 4676 | MockWrite data_writes1[] = { |
| 4677 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4678 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4679 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4680 | }; |
| 4681 | |
| 4682 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4683 | // connection. |
| 4684 | MockRead data_reads1[] = { |
| 4685 | // No credentials. |
| 4686 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4687 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4688 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4689 | }; |
| 4690 | |
| 4691 | // Since the first connection was closed, need to establish another once given |
| 4692 | // credentials. |
| 4693 | MockWrite data_writes2[] = { |
| 4694 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4695 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4696 | "Proxy-Connection: keep-alive\r\n" |
| 4697 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4698 | }; |
| 4699 | |
| 4700 | MockRead data_reads2[] = { |
| 4701 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4702 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4703 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4704 | }; |
| 4705 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4706 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4707 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4708 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4709 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4710 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4711 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4712 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4713 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4714 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4715 | |
| 4716 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4717 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4718 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4719 | |
| 4720 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4721 | ASSERT_TRUE(response); |
| 4722 | ASSERT_TRUE(response->headers); |
| 4723 | EXPECT_EQ(407, response->headers->response_code()); |
| 4724 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4725 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4726 | EXPECT_FALSE(response->auth_challenge); |
| 4727 | |
| 4728 | LoadTimingInfo load_timing_info; |
| 4729 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4730 | |
| 4731 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4732 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4733 | response = trans->GetResponseInfo(); |
| 4734 | ASSERT_TRUE(response); |
| 4735 | ASSERT_TRUE(response->headers); |
| 4736 | EXPECT_EQ(407, response->headers->response_code()); |
| 4737 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4738 | EXPECT_TRUE(response->auth_challenge); |
| 4739 | |
| 4740 | trans.reset(); |
| 4741 | session->CloseAllConnections(); |
| 4742 | } |
| 4743 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4744 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4745 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4746 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4747 | // authentication handshake can continue with the same scheme but with a |
| 4748 | // different identity. |
| 4749 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4750 | HttpRequestInfo request; |
| 4751 | request.method = "GET"; |
| 4752 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4753 | request.traffic_annotation = |
| 4754 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4755 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4756 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4757 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4758 | |
| 4759 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4760 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4761 | mock_handler->set_allows_default_credentials(true); |
| 4762 | mock_handler->set_allows_explicit_credentials(true); |
| 4763 | mock_handler->set_connection_based(true); |
| 4764 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4765 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4766 | HttpAuth::AUTH_SERVER); |
| 4767 | |
| 4768 | // Add another handler for the second challenge. It supports default |
| 4769 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4770 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4771 | mock_handler->set_allows_default_credentials(true); |
| 4772 | mock_handler->set_allows_explicit_credentials(true); |
| 4773 | mock_handler->set_connection_based(true); |
| 4774 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4775 | HttpAuth::AUTH_SERVER); |
| 4776 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4777 | |
| 4778 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4779 | |
| 4780 | MockWrite data_writes1[] = { |
| 4781 | MockWrite("GET / HTTP/1.1\r\n" |
| 4782 | "Host: www.example.org\r\n" |
| 4783 | "Connection: keep-alive\r\n\r\n"), |
| 4784 | }; |
| 4785 | |
| 4786 | MockRead data_reads1[] = { |
| 4787 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4788 | "WWW-Authenticate: Mock\r\n" |
| 4789 | "Connection: keep-alive\r\n\r\n"), |
| 4790 | }; |
| 4791 | |
| 4792 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4793 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4794 | // transaction procceds without an authorization header. |
| 4795 | MockWrite data_writes2[] = { |
| 4796 | MockWrite("GET / HTTP/1.1\r\n" |
| 4797 | "Host: www.example.org\r\n" |
| 4798 | "Connection: keep-alive\r\n\r\n"), |
| 4799 | }; |
| 4800 | |
| 4801 | MockRead data_reads2[] = { |
| 4802 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4803 | "WWW-Authenticate: Mock\r\n" |
| 4804 | "Connection: keep-alive\r\n\r\n"), |
| 4805 | }; |
| 4806 | |
| 4807 | MockWrite data_writes3[] = { |
| 4808 | MockWrite("GET / HTTP/1.1\r\n" |
| 4809 | "Host: www.example.org\r\n" |
| 4810 | "Connection: keep-alive\r\n" |
| 4811 | "Authorization: auth_token\r\n\r\n"), |
| 4812 | }; |
| 4813 | |
| 4814 | MockRead data_reads3[] = { |
| 4815 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4816 | "Content-Length: 5\r\n" |
| 4817 | "Content-Type: text/plain\r\n" |
| 4818 | "Connection: keep-alive\r\n\r\n" |
| 4819 | "Hello"), |
| 4820 | }; |
| 4821 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4822 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4823 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4824 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4825 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4826 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4827 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4828 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4829 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4830 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4831 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4832 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4833 | |
| 4834 | TestCompletionCallback callback; |
| 4835 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4836 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4837 | |
| 4838 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4839 | ASSERT_TRUE(response); |
| 4840 | ASSERT_TRUE(response->headers); |
| 4841 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4842 | |
| 4843 | // The following three tests assert that an authentication challenge was |
| 4844 | // received and that the stack is ready to respond to the challenge using |
| 4845 | // ambient credentials. |
| 4846 | EXPECT_EQ(401, response->headers->response_code()); |
| 4847 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4848 | EXPECT_FALSE(response->auth_challenge); |
| 4849 | |
| 4850 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4851 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4852 | response = trans->GetResponseInfo(); |
| 4853 | ASSERT_TRUE(response); |
| 4854 | ASSERT_TRUE(response->headers); |
| 4855 | |
| 4856 | // The following three tests assert that an authentication challenge was |
| 4857 | // received and that the stack needs explicit credentials before it is ready |
| 4858 | // to respond to the challenge. |
| 4859 | EXPECT_EQ(401, response->headers->response_code()); |
| 4860 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4861 | EXPECT_TRUE(response->auth_challenge); |
| 4862 | |
| 4863 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4864 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4865 | response = trans->GetResponseInfo(); |
| 4866 | ASSERT_TRUE(response); |
| 4867 | ASSERT_TRUE(response->headers); |
| 4868 | EXPECT_EQ(200, response->headers->response_code()); |
| 4869 | |
| 4870 | trans.reset(); |
| 4871 | session->CloseAllConnections(); |
| 4872 | } |
| 4873 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4874 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4875 | // schemes, based on the path of the URL being requests. |
| 4876 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4877 | public: |
| 4878 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4879 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4880 | |
| 4881 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4882 | |
| 4883 | static HostPortPair ProxyHostPortPair() { |
| 4884 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4885 | } |
| 4886 | |
| 4887 | // ProxyResolver implementation. |
| 4888 | int GetProxyForURL(const GURL& url, |
| 4889 | ProxyInfo* results, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4890 | CompletionOnceCallback callback, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4891 | std::unique_ptr<Request>* request, |
| 4892 | const NetLogWithSource& /*net_log*/) override { |
| 4893 | *results = ProxyInfo(); |
Ramin Halavati | 921731ea | 2018-03-16 08:24:57 | [diff] [blame] | 4894 | results->set_traffic_annotation( |
| 4895 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4896 | if (url.path() == "/socks4") { |
| 4897 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 4898 | return OK; |
| 4899 | } |
| 4900 | if (url.path() == "/socks5") { |
| 4901 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 4902 | return OK; |
| 4903 | } |
| 4904 | if (url.path() == "/http") { |
| 4905 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 4906 | return OK; |
| 4907 | } |
| 4908 | if (url.path() == "/https") { |
| 4909 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 4910 | return OK; |
| 4911 | } |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 4912 | if (url.path() == "/https_trusted") { |
| 4913 | results->UseProxyServer(ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 4914 | ProxyHostPortPair(), |
| 4915 | true /* is_trusted_proxy */)); |
| 4916 | return OK; |
| 4917 | } |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4918 | NOTREACHED(); |
| 4919 | return ERR_NOT_IMPLEMENTED; |
| 4920 | } |
| 4921 | |
| 4922 | private: |
| 4923 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 4924 | }; |
| 4925 | |
| 4926 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 4927 | : public ProxyResolverFactory { |
| 4928 | public: |
| 4929 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 4930 | : ProxyResolverFactory(false) {} |
| 4931 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4932 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 4933 | std::unique_ptr<ProxyResolver>* resolver, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4934 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4935 | std::unique_ptr<Request>* request) override { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4936 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 4937 | return OK; |
| 4938 | } |
| 4939 | |
| 4940 | private: |
| 4941 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 4942 | }; |
| 4943 | |
| 4944 | // 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] | 4945 | // same address, the connections are not grouped together. i.e., a request to |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4946 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 4947 | // request to foo.com using proxy.com as an HTTP proxy. |
| 4948 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4949 | session_deps_.proxy_resolution_service = |
| 4950 | std::make_unique<ProxyResolutionService>( |
| 4951 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 4952 | ProxyConfig::CreateAutoDetect(), TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 4953 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 4954 | nullptr); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4955 | |
| 4956 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4957 | |
| 4958 | MockWrite socks_writes[] = { |
| 4959 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 4960 | kSOCKS4OkRequestLocalHostPort80Length), |
| 4961 | MockWrite(SYNCHRONOUS, |
| 4962 | "GET /socks4 HTTP/1.1\r\n" |
| 4963 | "Host: test\r\n" |
| 4964 | "Connection: keep-alive\r\n\r\n"), |
| 4965 | }; |
| 4966 | MockRead socks_reads[] = { |
| 4967 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 4968 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4969 | "Connection: keep-alive\r\n" |
| 4970 | "Content-Length: 15\r\n\r\n" |
| 4971 | "SOCKS4 Response"), |
| 4972 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4973 | StaticSocketDataProvider socks_data(socks_reads, socks_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4974 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 4975 | |
| 4976 | const char kSOCKS5Request[] = { |
| 4977 | 0x05, // Version |
| 4978 | 0x01, // Command (CONNECT) |
| 4979 | 0x00, // Reserved |
| 4980 | 0x03, // Address type (DOMAINNAME) |
| 4981 | 0x04, // Length of domain (4) |
| 4982 | 't', 'e', 's', 't', // Domain string |
| 4983 | 0x00, 0x50, // 16-bit port (80) |
| 4984 | }; |
| 4985 | MockWrite socks5_writes[] = { |
| 4986 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 4987 | MockWrite(ASYNC, kSOCKS5Request, base::size(kSOCKS5Request)), |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4988 | MockWrite(SYNCHRONOUS, |
| 4989 | "GET /socks5 HTTP/1.1\r\n" |
| 4990 | "Host: test\r\n" |
| 4991 | "Connection: keep-alive\r\n\r\n"), |
| 4992 | }; |
| 4993 | MockRead socks5_reads[] = { |
| 4994 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 4995 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 4996 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4997 | "Connection: keep-alive\r\n" |
| 4998 | "Content-Length: 15\r\n\r\n" |
| 4999 | "SOCKS5 Response"), |
| 5000 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5001 | StaticSocketDataProvider socks5_data(socks5_reads, socks5_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5002 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 5003 | |
| 5004 | MockWrite http_writes[] = { |
| 5005 | MockWrite(SYNCHRONOUS, |
| 5006 | "GET http://test/http HTTP/1.1\r\n" |
| 5007 | "Host: test\r\n" |
| 5008 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5009 | }; |
| 5010 | MockRead http_reads[] = { |
| 5011 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5012 | "Proxy-Connection: keep-alive\r\n" |
| 5013 | "Content-Length: 13\r\n\r\n" |
| 5014 | "HTTP Response"), |
| 5015 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5016 | StaticSocketDataProvider http_data(http_reads, http_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5017 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 5018 | |
| 5019 | MockWrite https_writes[] = { |
| 5020 | MockWrite(SYNCHRONOUS, |
| 5021 | "GET http://test/https HTTP/1.1\r\n" |
| 5022 | "Host: test\r\n" |
| 5023 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5024 | }; |
| 5025 | MockRead https_reads[] = { |
| 5026 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5027 | "Proxy-Connection: keep-alive\r\n" |
| 5028 | "Content-Length: 14\r\n\r\n" |
| 5029 | "HTTPS Response"), |
| 5030 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5031 | StaticSocketDataProvider https_data(https_reads, https_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5032 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 5033 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 5034 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5035 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5036 | MockWrite https_trusted_writes[] = { |
| 5037 | MockWrite(SYNCHRONOUS, |
| 5038 | "GET http://test/https_trusted HTTP/1.1\r\n" |
| 5039 | "Host: test\r\n" |
| 5040 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5041 | }; |
| 5042 | MockRead https_trusted_reads[] = { |
| 5043 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5044 | "Proxy-Connection: keep-alive\r\n" |
| 5045 | "Content-Length: 22\r\n\r\n" |
| 5046 | "HTTPS Trusted Response"), |
| 5047 | }; |
| 5048 | StaticSocketDataProvider trusted_https_data(https_trusted_reads, |
| 5049 | https_trusted_writes); |
| 5050 | session_deps_.socket_factory->AddSocketDataProvider(&trusted_https_data); |
| 5051 | SSLSocketDataProvider ssl2(SYNCHRONOUS, OK); |
| 5052 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 5053 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5054 | struct TestCase { |
| 5055 | GURL url; |
| 5056 | std::string expected_response; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5057 | // 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] | 5058 | // after the test. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5059 | int expected_idle_socks4_sockets; |
| 5060 | int expected_idle_socks5_sockets; |
| 5061 | // How many idle sockets there should be in the HTTP/HTTPS proxy socket |
| 5062 | // pools after the test. |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5063 | int expected_idle_http_sockets; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5064 | int expected_idle_https_sockets; |
| 5065 | // How many idle sockets there should be in the HTTPS proxy socket pool with |
| 5066 | // the ProxyServer's |is_trusted_proxy| bit set after the test. |
| 5067 | int expected_idle_trusted_https_sockets; |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5068 | } const kTestCases[] = { |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5069 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0, 0, 0, 0}, |
| 5070 | {GURL("http://test/socks5"), "SOCKS5 Response", 1, 1, 0, 0, 0}, |
| 5071 | {GURL("http://test/http"), "HTTP Response", 1, 1, 1, 0, 0}, |
| 5072 | {GURL("http://test/https"), "HTTPS Response", 1, 1, 1, 1, 0}, |
| 5073 | {GURL("http://test/https_trusted"), "HTTPS Trusted Response", 1, 1, 1, 1, |
| 5074 | 1}, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5075 | }; |
| 5076 | |
| 5077 | for (const auto& test_case : kTestCases) { |
| 5078 | HttpRequestInfo request; |
| 5079 | request.method = "GET"; |
| 5080 | request.url = test_case.url; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5081 | request.traffic_annotation = |
| 5082 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5083 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 5084 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 5085 | session.get()); |
| 5086 | TestCompletionCallback callback; |
| 5087 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 5088 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5089 | |
| 5090 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5091 | ASSERT_TRUE(response); |
| 5092 | ASSERT_TRUE(response->headers); |
| 5093 | EXPECT_EQ(200, response->headers->response_code()); |
| 5094 | std::string response_data; |
| 5095 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 5096 | EXPECT_EQ(test_case.expected_response, response_data); |
| 5097 | |
| 5098 | // Return the socket to the socket pool, so can make sure it's not used for |
| 5099 | // the next requests. |
| 5100 | trans.reset(); |
| 5101 | base::RunLoop().RunUntilIdle(); |
| 5102 | |
| 5103 | // Check the number of idle sockets in the pool, to make sure that used |
| 5104 | // sockets are indeed being returned to the socket pool. If each request |
| 5105 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 5106 | // pass. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5107 | EXPECT_EQ(test_case.expected_idle_socks4_sockets, |
| 5108 | session |
| 5109 | ->GetSocketPoolForSOCKSProxy( |
| 5110 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5111 | ProxyServer(ProxyServer::SCHEME_SOCKS4, |
| 5112 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5113 | ProxyHostPortPair())) |
| 5114 | ->IdleSocketCount()); |
| 5115 | EXPECT_EQ(test_case.expected_idle_socks5_sockets, |
| 5116 | session |
| 5117 | ->GetSocketPoolForSOCKSProxy( |
| 5118 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5119 | ProxyServer(ProxyServer::SCHEME_SOCKS5, |
| 5120 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5121 | ProxyHostPortPair())) |
| 5122 | ->IdleSocketCount()); |
| 5123 | EXPECT_EQ(test_case.expected_idle_http_sockets, |
| 5124 | session |
| 5125 | ->GetSocketPoolForHTTPLikeProxy( |
| 5126 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5127 | ProxyServer(ProxyServer::SCHEME_HTTP, |
| 5128 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5129 | ProxyHostPortPair())) |
| 5130 | ->IdleSocketCount()); |
| 5131 | EXPECT_EQ(test_case.expected_idle_https_sockets, |
| 5132 | session |
| 5133 | ->GetSocketPoolForHTTPLikeProxy( |
| 5134 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5135 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5136 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5137 | ProxyHostPortPair())) |
| 5138 | ->IdleSocketCount()); |
| 5139 | EXPECT_EQ(test_case.expected_idle_trusted_https_sockets, |
| 5140 | session |
| 5141 | ->GetSocketPoolForHTTPLikeProxy( |
| 5142 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5143 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5144 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5145 | ProxyHostPortPair(), |
| 5146 | true /* is_trusted_proxy */)) |
| 5147 | ->IdleSocketCount()); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5148 | } |
| 5149 | } |
| 5150 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5151 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5152 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5153 | HttpRequestInfo request1; |
| 5154 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5155 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5156 | request1.traffic_annotation = |
| 5157 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5158 | |
| 5159 | HttpRequestInfo request2; |
| 5160 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5161 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5162 | request2.traffic_annotation = |
| 5163 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5164 | |
| 5165 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5166 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5167 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5168 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5169 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5170 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5171 | |
| 5172 | // Since we have proxy, should try to establish tunnel. |
| 5173 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5174 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5175 | "Host: www.example.org:443\r\n" |
| 5176 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5177 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5178 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5179 | "Host: www.example.org\r\n" |
| 5180 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5181 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5182 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5183 | "Host: www.example.org\r\n" |
| 5184 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5185 | }; |
| 5186 | |
| 5187 | // The proxy responds to the connect with a 407, using a persistent |
| 5188 | // connection. |
| 5189 | MockRead data_reads1[] = { |
| 5190 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5191 | |
| 5192 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5193 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5194 | MockRead(SYNCHRONOUS, "1"), |
| 5195 | |
| 5196 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5197 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5198 | MockRead(SYNCHRONOUS, "22"), |
| 5199 | }; |
| 5200 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5201 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5202 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5203 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5204 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5205 | |
| 5206 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5207 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5208 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5209 | |
| 5210 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5211 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5212 | |
| 5213 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5214 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5215 | |
| 5216 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5217 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5218 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5219 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5220 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5221 | |
| 5222 | LoadTimingInfo load_timing_info1; |
| 5223 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5224 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5225 | |
| 5226 | trans1.reset(); |
| 5227 | |
| 5228 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5229 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5230 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5231 | |
| 5232 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5233 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5234 | |
| 5235 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5236 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5237 | |
| 5238 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5239 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5240 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5241 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5242 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5243 | |
| 5244 | LoadTimingInfo load_timing_info2; |
| 5245 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5246 | TestLoadTimingReused(load_timing_info2); |
| 5247 | |
| 5248 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5249 | |
| 5250 | trans2.reset(); |
| 5251 | session->CloseAllConnections(); |
| 5252 | } |
| 5253 | |
| 5254 | // 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] | 5255 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5256 | HttpRequestInfo request1; |
| 5257 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5258 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5259 | request1.traffic_annotation = |
| 5260 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5261 | |
| 5262 | HttpRequestInfo request2; |
| 5263 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5264 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5265 | request2.traffic_annotation = |
| 5266 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5267 | |
| 5268 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5269 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5270 | ProxyResolutionService::CreateFixedFromPacResult( |
| 5271 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5272 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5273 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5274 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5275 | |
| 5276 | // Since we have proxy, should try to establish tunnel. |
| 5277 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5278 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5279 | "Host: www.example.org:443\r\n" |
| 5280 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5281 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5282 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5283 | "Host: www.example.org\r\n" |
| 5284 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5285 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5286 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5287 | "Host: www.example.org\r\n" |
| 5288 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5289 | }; |
| 5290 | |
| 5291 | // The proxy responds to the connect with a 407, using a persistent |
| 5292 | // connection. |
| 5293 | MockRead data_reads1[] = { |
| 5294 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5295 | |
| 5296 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5297 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5298 | MockRead(SYNCHRONOUS, "1"), |
| 5299 | |
| 5300 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5301 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5302 | MockRead(SYNCHRONOUS, "22"), |
| 5303 | }; |
| 5304 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5305 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5306 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5307 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5308 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5309 | |
| 5310 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5311 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5312 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5313 | |
| 5314 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5315 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5316 | |
| 5317 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5318 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5319 | |
| 5320 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5321 | ASSERT_TRUE(response1); |
| 5322 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5323 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5324 | |
| 5325 | LoadTimingInfo load_timing_info1; |
| 5326 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5327 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 5328 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 5329 | |
| 5330 | trans1.reset(); |
| 5331 | |
| 5332 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5333 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5334 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5335 | |
| 5336 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5337 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5338 | |
| 5339 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5340 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5341 | |
| 5342 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5343 | ASSERT_TRUE(response2); |
| 5344 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5345 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5346 | |
| 5347 | LoadTimingInfo load_timing_info2; |
| 5348 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5349 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 5350 | |
| 5351 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5352 | |
| 5353 | trans2.reset(); |
| 5354 | session->CloseAllConnections(); |
| 5355 | } |
| 5356 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5357 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5358 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5359 | HttpRequestInfo request; |
| 5360 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5361 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5362 | request.traffic_annotation = |
| 5363 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5364 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5365 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5366 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5367 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5368 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5369 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5370 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5371 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5372 | // Since we have proxy, should use full url |
| 5373 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5374 | MockWrite( |
| 5375 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5376 | "Host: www.example.org\r\n" |
| 5377 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5378 | }; |
| 5379 | |
| 5380 | MockRead data_reads1[] = { |
| 5381 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5382 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5383 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5384 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5385 | }; |
| 5386 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5387 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5388 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5389 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5390 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5391 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5392 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5393 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5394 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5395 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5396 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5397 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5398 | |
| 5399 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5400 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5401 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5402 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5403 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5404 | TestLoadTimingNotReused(load_timing_info, |
| 5405 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5406 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5407 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5408 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5409 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5410 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5411 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5412 | EXPECT_EQ(200, response->headers->response_code()); |
| 5413 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5414 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5415 | |
| 5416 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5417 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5418 | } |
| 5419 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5420 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5421 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5422 | HttpRequestInfo request; |
| 5423 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5424 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5425 | request.traffic_annotation = |
| 5426 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5427 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5428 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5429 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5430 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5431 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5432 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5433 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5434 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5435 | // fetch http://www.example.org/ via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5436 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5437 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5438 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5439 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5440 | spdy::SpdySerializedFrame resp( |
| 5441 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 5442 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5443 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5444 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5445 | }; |
| 5446 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5447 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5448 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5449 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5450 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5451 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5452 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5453 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5454 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5455 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5456 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5457 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5458 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5459 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5460 | |
| 5461 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5462 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5463 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5464 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5465 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5466 | TestLoadTimingNotReused(load_timing_info, |
| 5467 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5468 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5469 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5470 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5471 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5472 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5473 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5474 | |
| 5475 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5476 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5477 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5478 | } |
| 5479 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5480 | // Verifies that a session which races and wins against the owning transaction |
| 5481 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5482 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5483 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5484 | HttpRequestInfo request; |
| 5485 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5486 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5487 | request.traffic_annotation = |
| 5488 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5489 | |
| 5490 | // Configure SPDY proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5491 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5492 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5493 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5494 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5495 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5496 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5497 | // Fetch http://www.example.org/ through the SPDY proxy. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5498 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5499 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5500 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5501 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5502 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 5503 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5504 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5505 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5506 | }; |
| 5507 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5508 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5509 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5510 | |
| 5511 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5512 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5513 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5514 | |
| 5515 | TestCompletionCallback callback1; |
| 5516 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5517 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5518 | |
| 5519 | // Stall the hostname resolution begun by the transaction. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5520 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5521 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5522 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5523 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5524 | |
| 5525 | // Race a session to the proxy, which completes first. |
| 5526 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 5527 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 5528 | PRIVACY_MODE_DISABLED, |
| 5529 | SpdySessionKey::IsProxySession::kTrue, SocketTag()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5530 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5531 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5532 | |
| 5533 | // Unstall the resolution begun by the transaction. |
| 5534 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5535 | session_deps_.host_resolver->ResolveAllPending(); |
| 5536 | |
| 5537 | EXPECT_FALSE(callback1.have_result()); |
| 5538 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5539 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5540 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5541 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5542 | ASSERT_TRUE(response); |
| 5543 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5544 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5545 | |
| 5546 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5547 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5548 | EXPECT_EQ(kUploadData, response_data); |
| 5549 | } |
| 5550 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5551 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5552 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5553 | HttpRequestInfo request; |
| 5554 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5555 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5556 | request.traffic_annotation = |
| 5557 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5558 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5559 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5560 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5561 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5562 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5563 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5564 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5565 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5566 | // The first request will be a bare GET, the second request will be a |
| 5567 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5568 | spdy_util_.set_default_url(request.url); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5569 | spdy::SpdySerializedFrame req_get( |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5570 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5571 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5572 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5573 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5574 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5575 | spdy::SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5576 | kExtraAuthorizationHeaders, base::size(kExtraAuthorizationHeaders) / 2, 3, |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5577 | LOWEST)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5578 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5579 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5580 | }; |
| 5581 | |
| 5582 | // The first response is a 407 proxy authentication challenge, and the second |
| 5583 | // response will be a 200 response since the second request includes a valid |
| 5584 | // Authorization header. |
| 5585 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5586 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5587 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5588 | spdy::SpdySerializedFrame resp_authentication( |
| 5589 | spdy_util_.ConstructSpdyReplyError( |
| 5590 | "407", kExtraAuthenticationHeaders, |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5591 | base::size(kExtraAuthenticationHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5592 | spdy::SpdySerializedFrame body_authentication( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5593 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5594 | spdy::SpdySerializedFrame resp_data( |
| 5595 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 5596 | spdy::SpdySerializedFrame body_data( |
| 5597 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5598 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5599 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5600 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5601 | CreateMockRead(resp_data, 4), |
| 5602 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5603 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5604 | }; |
| 5605 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5606 | SequencedSocketData data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5607 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5608 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5609 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5610 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5611 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5612 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5613 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5614 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5615 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5616 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5617 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5618 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5619 | |
| 5620 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5621 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5622 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5623 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5624 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5625 | ASSERT_TRUE(response); |
| 5626 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5627 | EXPECT_EQ(407, response->headers->response_code()); |
| 5628 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5629 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5630 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5631 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5632 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5633 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5634 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5635 | |
| 5636 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5637 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5638 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5639 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5640 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5641 | ASSERT_TRUE(response_restart); |
| 5642 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5643 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5644 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5645 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5646 | } |
| 5647 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5648 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5649 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5650 | HttpRequestInfo request; |
| 5651 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5652 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5653 | request.traffic_annotation = |
| 5654 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5655 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5656 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5657 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5658 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5659 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5660 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5661 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5662 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5663 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5664 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5665 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5666 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5667 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5668 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5669 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5670 | const char get[] = |
| 5671 | "GET / HTTP/1.1\r\n" |
| 5672 | "Host: www.example.org\r\n" |
| 5673 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5674 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5675 | spdy_util_.ConstructSpdyDataFrame(1, get, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5676 | spdy::SpdySerializedFrame conn_resp( |
| 5677 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5678 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5679 | "Content-Length: 10\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5680 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5681 | spdy_util_.ConstructSpdyDataFrame(1, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5682 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5683 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5684 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5685 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5686 | |
| 5687 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5688 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5689 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5690 | }; |
| 5691 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5692 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5693 | CreateMockRead(conn_resp, 1, ASYNC), |
| 5694 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 5695 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 5696 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5697 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5698 | }; |
| 5699 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5700 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5701 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5702 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5703 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5704 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5705 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5706 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5707 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5708 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5709 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5710 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5711 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5712 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5713 | |
| 5714 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5715 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5716 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5717 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5718 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5719 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5720 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5721 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5722 | ASSERT_TRUE(response); |
| 5723 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5724 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5725 | |
| 5726 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5727 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5728 | EXPECT_EQ("1234567890", response_data); |
| 5729 | } |
| 5730 | |
| 5731 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5732 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5733 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5734 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5735 | HttpRequestInfo request; |
| 5736 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5737 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5738 | request.traffic_annotation = |
| 5739 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5740 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5741 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5742 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5743 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5744 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5745 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5746 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5747 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5748 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5749 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5750 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5751 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5752 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5753 | // fetch https://www.example.org/ via SPDY |
| 5754 | const char kMyUrl[] = "https://www.example.org/"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5755 | spdy::SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5756 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5757 | spdy::SpdySerializedFrame wrapped_get( |
| 5758 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 5759 | spdy::SpdySerializedFrame conn_resp( |
| 5760 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 5761 | spdy::SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5762 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5763 | spdy::SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5764 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5765 | spdy::SpdySerializedFrame body( |
| 5766 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5767 | spdy::SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5768 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5769 | spdy::SpdySerializedFrame window_update_get_resp( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5770 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5771 | spdy::SpdySerializedFrame window_update_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5772 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5773 | |
| 5774 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5775 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5776 | CreateMockWrite(window_update_get_resp, 6), |
| 5777 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5778 | }; |
| 5779 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5780 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5781 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5782 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5783 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5784 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5785 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5786 | }; |
| 5787 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5788 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5789 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5790 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5791 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5792 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5793 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5794 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5795 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5796 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5797 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5798 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5799 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5800 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5801 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5802 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5803 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5804 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5805 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5806 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5807 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5808 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5809 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5810 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5811 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5812 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5813 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5814 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5815 | ASSERT_TRUE(response); |
| 5816 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5817 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5818 | |
| 5819 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5820 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5821 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5822 | } |
| 5823 | |
| 5824 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5825 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5826 | HttpRequestInfo request; |
| 5827 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5828 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5829 | request.traffic_annotation = |
| 5830 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5831 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5832 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5833 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5834 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5835 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5836 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5837 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5838 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5839 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5840 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5841 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5842 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5843 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5844 | spdy::SpdySerializedFrame get( |
| 5845 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5846 | |
| 5847 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5848 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5849 | }; |
| 5850 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5851 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
| 5852 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5853 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5854 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5855 | }; |
| 5856 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5857 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5858 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5859 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5860 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5861 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5862 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5863 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5864 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5865 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5866 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5867 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5868 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5869 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5870 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5871 | |
| 5872 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5873 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5874 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5875 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5876 | } |
| 5877 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5878 | // Test the case where a proxied H2 session doesn't exist when an auth challenge |
| 5879 | // is observed, but does exist by the time auth credentials are provided. |
| 5880 | // Proxy-Connection: Close is used so that there's a second DNS lookup, which is |
| 5881 | // what causes the existing H2 session to be noticed and reused. |
| 5882 | TEST_F(HttpNetworkTransactionTest, ProxiedH2SessionAppearsDuringAuth) { |
| 5883 | ProxyConfig proxy_config; |
| 5884 | proxy_config.set_auto_detect(true); |
| 5885 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 5886 | |
| 5887 | CapturingProxyResolver capturing_proxy_resolver; |
| 5888 | capturing_proxy_resolver.set_proxy_server( |
| 5889 | ProxyServer(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 70))); |
| 5890 | session_deps_.proxy_resolution_service = |
| 5891 | std::make_unique<ProxyResolutionService>( |
| 5892 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 5893 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 5894 | std::make_unique<CapturingProxyResolverFactory>( |
| 5895 | &capturing_proxy_resolver), |
| 5896 | nullptr); |
| 5897 | |
| 5898 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 5899 | |
| 5900 | const char kMyUrl[] = "https://www.example.org/"; |
| 5901 | spdy::SpdySerializedFrame get(spdy_util_.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 5902 | spdy::SpdySerializedFrame get_resp( |
| 5903 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 5904 | spdy::SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 5905 | |
| 5906 | spdy_util_.UpdateWithStreamDestruction(1); |
| 5907 | spdy::SpdySerializedFrame get2( |
| 5908 | spdy_util_.ConstructSpdyGet(kMyUrl, 3, LOWEST)); |
| 5909 | spdy::SpdySerializedFrame get_resp2( |
| 5910 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 5911 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
| 5912 | |
| 5913 | MockWrite auth_challenge_writes[] = { |
| 5914 | MockWrite(ASYNC, 0, |
| 5915 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5916 | "Host: www.example.org:443\r\n" |
| 5917 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5918 | }; |
| 5919 | |
| 5920 | MockRead auth_challenge_reads[] = { |
| 5921 | MockRead(ASYNC, 1, |
| 5922 | "HTTP/1.1 407 Authentication Required\r\n" |
| 5923 | "Content-Length: 0\r\n" |
| 5924 | "Proxy-Connection: close\r\n" |
| 5925 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
| 5926 | }; |
| 5927 | |
| 5928 | MockWrite spdy_writes[] = { |
| 5929 | MockWrite(ASYNC, 0, |
| 5930 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5931 | "Host: www.example.org:443\r\n" |
| 5932 | "Proxy-Connection: keep-alive\r\n" |
| 5933 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5934 | CreateMockWrite(get, 2), |
| 5935 | CreateMockWrite(get2, 5), |
| 5936 | }; |
| 5937 | |
| 5938 | MockRead spdy_reads[] = { |
| 5939 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 5940 | CreateMockRead(get_resp, 3, ASYNC), |
| 5941 | CreateMockRead(body, 4, ASYNC), |
| 5942 | CreateMockRead(get_resp2, 6, ASYNC), |
| 5943 | CreateMockRead(body2, 7, ASYNC), |
| 5944 | |
| 5945 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8), |
| 5946 | }; |
| 5947 | |
| 5948 | SequencedSocketData auth_challenge1(auth_challenge_reads, |
| 5949 | auth_challenge_writes); |
| 5950 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge1); |
| 5951 | |
| 5952 | SequencedSocketData auth_challenge2(auth_challenge_reads, |
| 5953 | auth_challenge_writes); |
| 5954 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge2); |
| 5955 | |
| 5956 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
| 5957 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5958 | |
| 5959 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5960 | ssl.next_proto = kProtoHTTP2; |
| 5961 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5962 | |
| 5963 | TestCompletionCallback callback; |
| 5964 | std::string response_data; |
| 5965 | |
| 5966 | // Run first request until an auth challenge is observed. |
| 5967 | HttpRequestInfo request1; |
| 5968 | request1.method = "GET"; |
| 5969 | request1.url = GURL(kMyUrl); |
| 5970 | request1.traffic_annotation = |
| 5971 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5972 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 5973 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 5974 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5975 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 5976 | ASSERT_TRUE(response); |
| 5977 | ASSERT_TRUE(response->headers); |
| 5978 | EXPECT_EQ(407, response->headers->response_code()); |
| 5979 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5980 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 5981 | |
| 5982 | // Run second request until an auth challenge is observed. |
| 5983 | HttpRequestInfo request2; |
| 5984 | request2.method = "GET"; |
| 5985 | request2.url = GURL(kMyUrl); |
| 5986 | request2.traffic_annotation = |
| 5987 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5988 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 5989 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 5990 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5991 | response = trans2.GetResponseInfo(); |
| 5992 | ASSERT_TRUE(response); |
| 5993 | ASSERT_TRUE(response->headers); |
| 5994 | EXPECT_EQ(407, response->headers->response_code()); |
| 5995 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5996 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 5997 | |
| 5998 | // Now provide credentials for the first request, and wait for it to complete. |
| 5999 | rv = trans1.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6000 | rv = callback.GetResult(rv); |
| 6001 | EXPECT_THAT(rv, IsOk()); |
| 6002 | response = trans1.GetResponseInfo(); |
| 6003 | ASSERT_TRUE(response); |
| 6004 | ASSERT_TRUE(response->headers); |
| 6005 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6006 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6007 | EXPECT_EQ(kUploadData, response_data); |
| 6008 | |
| 6009 | // Now provide credentials for the second request. It should notice the |
| 6010 | // existing session, and reuse it. |
| 6011 | rv = trans2.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6012 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6013 | response = trans2.GetResponseInfo(); |
| 6014 | ASSERT_TRUE(response); |
| 6015 | ASSERT_TRUE(response->headers); |
| 6016 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6017 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6018 | EXPECT_EQ(kUploadData, response_data); |
| 6019 | } |
| 6020 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6021 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6022 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6023 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6024 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 6025 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6026 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6027 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6028 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6029 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6030 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6031 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6032 | |
| 6033 | HttpRequestInfo request1; |
| 6034 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6035 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6036 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6037 | request1.traffic_annotation = |
| 6038 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6039 | |
| 6040 | HttpRequestInfo request2; |
| 6041 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6042 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6043 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6044 | request2.traffic_annotation = |
| 6045 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6046 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6047 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6048 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6049 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6050 | spdy::SpdySerializedFrame conn_resp1( |
| 6051 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6052 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6053 | // Fetch https://www.example.org/ via HTTP. |
| 6054 | const char get1[] = |
| 6055 | "GET / HTTP/1.1\r\n" |
| 6056 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6057 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6058 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6059 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6060 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6061 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6062 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6063 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6064 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6065 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6066 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6067 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6068 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6069 | // CONNECT to mail.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6070 | spdy::SpdyHeaderBlock connect2_block; |
| 6071 | connect2_block[spdy::kHttp2MethodHeader] = "CONNECT"; |
| 6072 | connect2_block[spdy::kHttp2AuthorityHeader] = "mail.example.org:443"; |
| 6073 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6074 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 6075 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6076 | spdy::SpdySerializedFrame conn_resp2( |
| 6077 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6078 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6079 | // Fetch https://mail.example.org/ via HTTP. |
| 6080 | const char get2[] = |
| 6081 | "GET / HTTP/1.1\r\n" |
| 6082 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6083 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6084 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6085 | spdy_util_.ConstructSpdyDataFrame(3, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6086 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6087 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6088 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6089 | spdy_util_.ConstructSpdyDataFrame(3, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6090 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6091 | spdy_util_.ConstructSpdyDataFrame(3, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6092 | |
| 6093 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6094 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6095 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6096 | }; |
| 6097 | |
| 6098 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6099 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6100 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 6101 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 6102 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 6103 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 6104 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 6105 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6106 | }; |
| 6107 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6108 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6109 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6110 | |
| 6111 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6112 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6113 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6114 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6115 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6116 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6117 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6118 | |
| 6119 | TestCompletionCallback callback; |
| 6120 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6121 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6122 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6123 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6124 | |
| 6125 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6126 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6127 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6128 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6129 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6130 | ASSERT_TRUE(response); |
| 6131 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6132 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6133 | |
| 6134 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6135 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6136 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6137 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6138 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6139 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6140 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6141 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6142 | |
| 6143 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6144 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6145 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 6146 | // to be created, so the socket's load timing looks like a fresh connection. |
| 6147 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6148 | |
| 6149 | // The requests should have different IDs, since they each are using their own |
| 6150 | // separate stream. |
| 6151 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6152 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6153 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6154 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6155 | } |
| 6156 | |
| 6157 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6158 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6159 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6160 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 6161 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6162 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6163 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6164 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6165 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6166 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6167 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6168 | |
| 6169 | HttpRequestInfo request1; |
| 6170 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6171 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6172 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6173 | request1.traffic_annotation = |
| 6174 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6175 | |
| 6176 | HttpRequestInfo request2; |
| 6177 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6178 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6179 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6180 | request2.traffic_annotation = |
| 6181 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6182 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6183 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6184 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6185 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6186 | spdy::SpdySerializedFrame conn_resp1( |
| 6187 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6188 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6189 | // Fetch https://www.example.org/ via HTTP. |
| 6190 | const char get1[] = |
| 6191 | "GET / HTTP/1.1\r\n" |
| 6192 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6193 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6194 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6195 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6196 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6197 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6198 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6199 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6200 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6201 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6202 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6203 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6204 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6205 | // Fetch https://www.example.org/2 via HTTP. |
| 6206 | const char get2[] = |
| 6207 | "GET /2 HTTP/1.1\r\n" |
| 6208 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6209 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6210 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6211 | spdy_util_.ConstructSpdyDataFrame(1, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6212 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6213 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6214 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6215 | spdy_util_.ConstructSpdyDataFrame(1, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6216 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6217 | spdy_util_.ConstructSpdyDataFrame(1, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6218 | |
| 6219 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6220 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6221 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6222 | }; |
| 6223 | |
| 6224 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6225 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6226 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6227 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6228 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6229 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6230 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6231 | }; |
| 6232 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6233 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6234 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6235 | |
| 6236 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6237 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6238 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6239 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6240 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6241 | |
| 6242 | TestCompletionCallback callback; |
| 6243 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6244 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6245 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6246 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6247 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6248 | |
| 6249 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6250 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6251 | |
| 6252 | LoadTimingInfo load_timing_info; |
| 6253 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6254 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6255 | |
| 6256 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6257 | ASSERT_TRUE(response); |
| 6258 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6259 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6260 | |
| 6261 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6262 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6263 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6264 | trans.reset(); |
| 6265 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6266 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6267 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6268 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6269 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6270 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6271 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6272 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6273 | |
| 6274 | LoadTimingInfo load_timing_info2; |
| 6275 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 6276 | TestLoadTimingReused(load_timing_info2); |
| 6277 | |
| 6278 | // The requests should have the same ID. |
| 6279 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6280 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6281 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6282 | } |
| 6283 | |
| 6284 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 6285 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6286 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6287 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6288 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6289 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6290 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6291 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6292 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6293 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6294 | |
| 6295 | HttpRequestInfo request1; |
| 6296 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6297 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6298 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6299 | request1.traffic_annotation = |
| 6300 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6301 | |
| 6302 | HttpRequestInfo request2; |
| 6303 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6304 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6305 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6306 | request2.traffic_annotation = |
| 6307 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6308 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6309 | // http://www.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6310 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6311 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6312 | spdy::SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6313 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6314 | spdy::SpdySerializedFrame get_resp1( |
| 6315 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 6316 | spdy::SpdySerializedFrame body1( |
| 6317 | spdy_util_.ConstructSpdyDataFrame(1, "1", true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 6318 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6319 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6320 | // http://mail.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6321 | spdy::SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6322 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6323 | spdy::SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6324 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6325 | spdy::SpdySerializedFrame get_resp2( |
| 6326 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 6327 | spdy::SpdySerializedFrame body2( |
| 6328 | spdy_util_.ConstructSpdyDataFrame(3, "22", true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6329 | |
| 6330 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6331 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6332 | }; |
| 6333 | |
| 6334 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6335 | CreateMockRead(get_resp1, 1, ASYNC), |
| 6336 | CreateMockRead(body1, 2, ASYNC), |
| 6337 | CreateMockRead(get_resp2, 4, ASYNC), |
| 6338 | CreateMockRead(body2, 5, ASYNC), |
| 6339 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6340 | }; |
| 6341 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6342 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6343 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6344 | |
| 6345 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6346 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6347 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6348 | |
| 6349 | TestCompletionCallback callback; |
| 6350 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6351 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6352 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6353 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6354 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6355 | |
| 6356 | LoadTimingInfo load_timing_info; |
| 6357 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6358 | TestLoadTimingNotReused(load_timing_info, |
| 6359 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6360 | |
| 6361 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6362 | ASSERT_TRUE(response); |
| 6363 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6364 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6365 | |
| 6366 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6367 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6368 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 6369 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6370 | // Delete the first request, so the second one can reuse the socket. |
| 6371 | trans.reset(); |
| 6372 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6373 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6374 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6375 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6376 | |
| 6377 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6378 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6379 | TestLoadTimingReused(load_timing_info2); |
| 6380 | |
| 6381 | // The requests should have the same ID. |
| 6382 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6383 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6384 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6385 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6386 | } |
| 6387 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6388 | // Test that an HTTP/2 CONNECT through an HTTPS Proxy to a HTTP/2 server and a |
| 6389 | // direct (non-proxied) request to the proxy server are not pooled, as that |
| 6390 | // would break socket pool isolation. |
| 6391 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation1) { |
| 6392 | ProxyConfig proxy_config; |
| 6393 | proxy_config.set_auto_detect(true); |
| 6394 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6395 | |
| 6396 | CapturingProxyResolver capturing_proxy_resolver; |
| 6397 | session_deps_.proxy_resolution_service = |
| 6398 | std::make_unique<ProxyResolutionService>( |
| 6399 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6400 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6401 | std::make_unique<CapturingProxyResolverFactory>( |
| 6402 | &capturing_proxy_resolver), |
| 6403 | nullptr); |
| 6404 | |
| 6405 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6406 | |
| 6407 | SpdyTestUtil spdy_util1; |
| 6408 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6409 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
| 6410 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 6411 | // fetch https://www.example.org/ via HTTP/2. |
| 6412 | const char kMyUrl[] = "https://www.example.org/"; |
| 6413 | spdy::SpdySerializedFrame get(spdy_util1.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6414 | spdy::SpdySerializedFrame wrapped_get( |
| 6415 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6416 | spdy::SpdySerializedFrame conn_resp( |
| 6417 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 6418 | spdy::SpdySerializedFrame get_resp( |
| 6419 | spdy_util1.ConstructSpdyGetReply(NULL, 0, 1)); |
| 6420 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6421 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6422 | spdy::SpdySerializedFrame body(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6423 | spdy::SpdySerializedFrame wrapped_body( |
| 6424 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6425 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6426 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6427 | spdy::SpdySerializedFrame window_update_body( |
| 6428 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6429 | |
| 6430 | MockWrite spdy_writes1[] = { |
| 6431 | CreateMockWrite(connect, 0), |
| 6432 | CreateMockWrite(wrapped_get, 2), |
| 6433 | CreateMockWrite(window_update_get_resp, 6), |
| 6434 | CreateMockWrite(window_update_body, 7), |
| 6435 | }; |
| 6436 | |
| 6437 | MockRead spdy_reads1[] = { |
| 6438 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6439 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6440 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6441 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6442 | MockRead(ASYNC, 0, 8), |
| 6443 | }; |
| 6444 | |
| 6445 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6446 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6447 | |
| 6448 | // Fetch https://proxy:70/ via HTTP/2. Needs a new SpdyTestUtil, since it uses |
| 6449 | // a new pipe. |
| 6450 | SpdyTestUtil spdy_util2; |
| 6451 | spdy::SpdySerializedFrame req( |
| 6452 | spdy_util2.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6453 | MockWrite spdy_writes2[] = {CreateMockWrite(req, 0)}; |
| 6454 | |
| 6455 | spdy::SpdySerializedFrame resp( |
| 6456 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6457 | spdy::SpdySerializedFrame data(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6458 | MockRead spdy_reads2[] = { |
| 6459 | CreateMockRead(resp, 1), |
| 6460 | CreateMockRead(data, 2), |
| 6461 | MockRead(ASYNC, 0, 3), |
| 6462 | }; |
| 6463 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6464 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6465 | |
| 6466 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6467 | ssl.next_proto = kProtoHTTP2; |
| 6468 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6469 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6470 | ssl2.next_proto = kProtoHTTP2; |
| 6471 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6472 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6473 | ssl3.next_proto = kProtoHTTP2; |
| 6474 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6475 | |
| 6476 | TestCompletionCallback callback; |
| 6477 | std::string response_data; |
| 6478 | |
| 6479 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6480 | capturing_proxy_resolver.set_proxy_server( |
| 6481 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6482 | HttpRequestInfo request1; |
| 6483 | request1.method = "GET"; |
| 6484 | request1.url = GURL("https://www.example.org/"); |
| 6485 | request1.traffic_annotation = |
| 6486 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6487 | |
| 6488 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6489 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 6490 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6491 | |
| 6492 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6493 | base::RunLoop().RunUntilIdle(); |
| 6494 | // Now allow the read of the response to complete. |
| 6495 | spdy_data1.Resume(); |
| 6496 | rv = callback.WaitForResult(); |
| 6497 | EXPECT_THAT(rv, IsOk()); |
| 6498 | |
| 6499 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 6500 | ASSERT_TRUE(response); |
| 6501 | ASSERT_TRUE(response->headers); |
| 6502 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6503 | |
| 6504 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6505 | EXPECT_EQ(kUploadData, response_data); |
| 6506 | RunUntilIdle(); |
| 6507 | |
| 6508 | // Make a direct HTTP/2 request to proxy:70. |
| 6509 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6510 | HttpRequestInfo request2; |
| 6511 | request2.method = "GET"; |
| 6512 | request2.url = GURL("https://proxy:70/"); |
| 6513 | request2.traffic_annotation = |
| 6514 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6515 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6516 | EXPECT_THAT(callback.GetResult(trans2.Start(&request2, callback.callback(), |
| 6517 | NetLogWithSource())), |
| 6518 | IsOk()); |
| 6519 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6520 | } |
| 6521 | |
| 6522 | // Same as above, but reverse request order, since the code to check for an |
| 6523 | // existing session is different for tunnels and direct connections. |
| 6524 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation2) { |
| 6525 | // Configure against https proxy server "myproxy:80". |
| 6526 | ProxyConfig proxy_config; |
| 6527 | proxy_config.set_auto_detect(true); |
| 6528 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6529 | |
| 6530 | CapturingProxyResolver capturing_proxy_resolver; |
| 6531 | session_deps_.proxy_resolution_service = |
| 6532 | std::make_unique<ProxyResolutionService>( |
| 6533 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6534 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6535 | std::make_unique<CapturingProxyResolverFactory>( |
| 6536 | &capturing_proxy_resolver), |
| 6537 | nullptr); |
| 6538 | |
| 6539 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6540 | // Fetch https://proxy:70/ via HTTP/2. |
| 6541 | SpdyTestUtil spdy_util1; |
| 6542 | spdy::SpdySerializedFrame req( |
| 6543 | spdy_util1.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6544 | MockWrite spdy_writes1[] = {CreateMockWrite(req, 0)}; |
| 6545 | |
| 6546 | spdy::SpdySerializedFrame resp( |
| 6547 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6548 | spdy::SpdySerializedFrame data(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6549 | MockRead spdy_reads1[] = { |
| 6550 | CreateMockRead(resp, 1), |
| 6551 | CreateMockRead(data, 2), |
| 6552 | MockRead(ASYNC, 0, 3), |
| 6553 | }; |
| 6554 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6555 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6556 | |
| 6557 | SpdyTestUtil spdy_util2; |
| 6558 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6559 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
| 6560 | nullptr, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 6561 | // fetch https://www.example.org/ via HTTP/2. |
| 6562 | const char kMyUrl[] = "https://www.example.org/"; |
| 6563 | spdy::SpdySerializedFrame get(spdy_util2.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6564 | spdy::SpdySerializedFrame wrapped_get( |
| 6565 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6566 | spdy::SpdySerializedFrame conn_resp( |
| 6567 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6568 | spdy::SpdySerializedFrame get_resp( |
| 6569 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6570 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6571 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6572 | spdy::SpdySerializedFrame body(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6573 | spdy::SpdySerializedFrame wrapped_body( |
| 6574 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6575 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6576 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6577 | spdy::SpdySerializedFrame window_update_body( |
| 6578 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6579 | |
| 6580 | MockWrite spdy_writes2[] = { |
| 6581 | CreateMockWrite(connect, 0), |
| 6582 | CreateMockWrite(wrapped_get, 2), |
| 6583 | CreateMockWrite(window_update_get_resp, 6), |
| 6584 | CreateMockWrite(window_update_body, 7), |
| 6585 | }; |
| 6586 | |
| 6587 | MockRead spdy_reads2[] = { |
| 6588 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6589 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6590 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6591 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6592 | MockRead(ASYNC, 0, 8), |
| 6593 | }; |
| 6594 | |
| 6595 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6596 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6597 | |
| 6598 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6599 | ssl.next_proto = kProtoHTTP2; |
| 6600 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6601 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6602 | ssl2.next_proto = kProtoHTTP2; |
| 6603 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6604 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6605 | ssl3.next_proto = kProtoHTTP2; |
| 6606 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6607 | |
| 6608 | TestCompletionCallback callback; |
| 6609 | std::string response_data; |
| 6610 | |
| 6611 | // Make a direct HTTP/2 request to proxy:70. |
| 6612 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6613 | HttpRequestInfo request1; |
| 6614 | request1.method = "GET"; |
| 6615 | request1.url = GURL("https://proxy:70/"); |
| 6616 | request1.traffic_annotation = |
| 6617 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6618 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6619 | EXPECT_THAT(callback.GetResult(trans1.Start(&request1, callback.callback(), |
| 6620 | NetLogWithSource())), |
| 6621 | IsOk()); |
| 6622 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6623 | RunUntilIdle(); |
| 6624 | |
| 6625 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6626 | capturing_proxy_resolver.set_proxy_server( |
| 6627 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6628 | HttpRequestInfo request2; |
| 6629 | request2.method = "GET"; |
| 6630 | request2.url = GURL("https://www.example.org/"); |
| 6631 | request2.traffic_annotation = |
| 6632 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6633 | |
| 6634 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6635 | int rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6636 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6637 | |
| 6638 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6639 | base::RunLoop().RunUntilIdle(); |
| 6640 | // Now allow the read of the response to complete. |
| 6641 | spdy_data2.Resume(); |
| 6642 | rv = callback.WaitForResult(); |
| 6643 | EXPECT_THAT(rv, IsOk()); |
| 6644 | |
| 6645 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 6646 | ASSERT_TRUE(response2); |
| 6647 | ASSERT_TRUE(response2->headers); |
| 6648 | EXPECT_EQ("HTTP/1.1 200", response2->headers->GetStatusLine()); |
| 6649 | |
| 6650 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6651 | EXPECT_EQ(kUploadData, response_data); |
| 6652 | } |
| 6653 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6654 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6655 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6656 | HttpRequestInfo request; |
| 6657 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6658 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6659 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6660 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6661 | request.traffic_annotation = |
| 6662 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6663 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6664 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6665 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6666 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6667 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6668 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6669 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6670 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6671 | // Since we have proxy, should use full url |
| 6672 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6673 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6674 | "Host: www.example.org\r\n" |
| 6675 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6676 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6677 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6678 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6679 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6680 | "Host: www.example.org\r\n" |
| 6681 | "Proxy-Connection: keep-alive\r\n" |
| 6682 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6683 | }; |
| 6684 | |
| 6685 | // The proxy responds to the GET with a 407, using a persistent |
| 6686 | // connection. |
| 6687 | MockRead data_reads1[] = { |
| 6688 | // No credentials. |
| 6689 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 6690 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6691 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 6692 | MockRead("Content-Length: 0\r\n\r\n"), |
| 6693 | |
| 6694 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6695 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6696 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6697 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6698 | }; |
| 6699 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6700 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6701 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6702 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6703 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6704 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6705 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6706 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6707 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6708 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6709 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6710 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6711 | |
| 6712 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6713 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6714 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6715 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6716 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6717 | TestLoadTimingNotReused(load_timing_info, |
| 6718 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6719 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6720 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6721 | ASSERT_TRUE(response); |
| 6722 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6723 | EXPECT_EQ(407, response->headers->response_code()); |
| 6724 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 6725 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6726 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6727 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6728 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6729 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6730 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6731 | |
| 6732 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6733 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6734 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6735 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6736 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6737 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 6738 | TestLoadTimingReused(load_timing_info); |
| 6739 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6740 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6741 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6742 | |
| 6743 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6744 | EXPECT_EQ(200, response->headers->response_code()); |
| 6745 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6746 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6747 | |
| 6748 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6749 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6750 | } |
| 6751 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6752 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6753 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6754 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6755 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6756 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6757 | request.traffic_annotation = |
| 6758 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6759 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6760 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6761 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6762 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6763 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6764 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6765 | // Since we have proxy, should try to establish tunnel. |
| 6766 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6767 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6768 | "Host: www.example.org:443\r\n" |
| 6769 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6770 | }; |
| 6771 | |
| 6772 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6773 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 6774 | // No response body because the test stops reading here. |
| 6775 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6776 | }; |
| 6777 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6778 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6779 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6780 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6781 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6782 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6783 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6784 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6785 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6786 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6787 | |
| 6788 | rv = callback.WaitForResult(); |
| 6789 | EXPECT_EQ(expected_status, rv); |
| 6790 | } |
| 6791 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6792 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6793 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6794 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6795 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6796 | } |
| 6797 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6798 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6799 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 6800 | } |
| 6801 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6802 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6803 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 6804 | } |
| 6805 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6806 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6807 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 6808 | } |
| 6809 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6810 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6811 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 6812 | } |
| 6813 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6814 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6815 | ConnectStatusHelper( |
| 6816 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 6817 | } |
| 6818 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6819 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6820 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 6821 | } |
| 6822 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6823 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6824 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 6825 | } |
| 6826 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6827 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6828 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 6829 | } |
| 6830 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6831 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6832 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 6833 | } |
| 6834 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6835 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6836 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 6837 | } |
| 6838 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6839 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6840 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 6841 | } |
| 6842 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6843 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6844 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 6845 | } |
| 6846 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6847 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6848 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 6849 | } |
| 6850 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6851 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6852 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 6853 | } |
| 6854 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6855 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6856 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 6857 | } |
| 6858 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6859 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6860 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 6861 | } |
| 6862 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6863 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 6864 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 6865 | } |
| 6866 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6867 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6868 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 6869 | } |
| 6870 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6871 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6872 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 6873 | } |
| 6874 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6875 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6876 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 6877 | } |
| 6878 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6879 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6880 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 6881 | } |
| 6882 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6883 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6884 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 6885 | } |
| 6886 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6887 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6888 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 6889 | } |
| 6890 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6891 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6892 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 6893 | } |
| 6894 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6895 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6896 | ConnectStatusHelperWithExpectedStatus( |
| 6897 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 6898 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6899 | } |
| 6900 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6901 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6902 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 6903 | } |
| 6904 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6905 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6906 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 6907 | } |
| 6908 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6909 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6910 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 6911 | } |
| 6912 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6913 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6914 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 6915 | } |
| 6916 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6917 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6918 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 6919 | } |
| 6920 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6921 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6922 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 6923 | } |
| 6924 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6925 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6926 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 6927 | } |
| 6928 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6929 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6930 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 6931 | } |
| 6932 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6933 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6934 | ConnectStatusHelper( |
| 6935 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 6936 | } |
| 6937 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6938 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6939 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 6940 | } |
| 6941 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6942 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6943 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 6944 | } |
| 6945 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6946 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6947 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 6948 | } |
| 6949 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6950 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6951 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 6952 | } |
| 6953 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6954 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6955 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 6956 | } |
| 6957 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6958 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6959 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 6960 | } |
| 6961 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6962 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6963 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 6964 | } |
| 6965 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6966 | // Test the flow when both the proxy server AND origin server require |
| 6967 | // authentication. Again, this uses basic auth for both since that is |
| 6968 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6969 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6970 | HttpRequestInfo request; |
| 6971 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6972 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6973 | request.traffic_annotation = |
| 6974 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6975 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6976 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6977 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6978 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6979 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6980 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6981 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6982 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6983 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6984 | MockWrite( |
| 6985 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6986 | "Host: www.example.org\r\n" |
| 6987 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6988 | }; |
| 6989 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6990 | MockRead data_reads1[] = { |
| 6991 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 6992 | // Give a couple authenticate options (only the middle one is actually |
| 6993 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 6994 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6995 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6996 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 6997 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6998 | // Large content-length -- won't matter, as connection will be reset. |
| 6999 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7000 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7001 | }; |
| 7002 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7003 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7004 | // request we should be issuing -- the final header line contains the |
| 7005 | // proxy's credentials. |
| 7006 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7007 | MockWrite( |
| 7008 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7009 | "Host: www.example.org\r\n" |
| 7010 | "Proxy-Connection: keep-alive\r\n" |
| 7011 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7012 | }; |
| 7013 | |
| 7014 | // Now the proxy server lets the request pass through to origin server. |
| 7015 | // The origin server responds with a 401. |
| 7016 | MockRead data_reads2[] = { |
| 7017 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7018 | // Note: We are using the same realm-name as the proxy server. This is |
| 7019 | // completely valid, as realms are unique across hosts. |
| 7020 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7021 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7022 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7023 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7024 | }; |
| 7025 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7026 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7027 | // the credentials for both the proxy and origin server. |
| 7028 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7029 | MockWrite( |
| 7030 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7031 | "Host: www.example.org\r\n" |
| 7032 | "Proxy-Connection: keep-alive\r\n" |
| 7033 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 7034 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7035 | }; |
| 7036 | |
| 7037 | // Lastly we get the desired content. |
| 7038 | MockRead data_reads3[] = { |
| 7039 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7040 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7041 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7042 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7043 | }; |
| 7044 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7045 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7046 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7047 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7048 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7049 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7050 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7051 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7052 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7053 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7054 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7055 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7056 | |
| 7057 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7058 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7059 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7060 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7061 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7062 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7063 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7064 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7065 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7066 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7067 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7068 | |
| 7069 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7070 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7071 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7072 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7073 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7074 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7075 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7076 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7077 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7078 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7079 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7080 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7081 | |
| 7082 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7083 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7084 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7085 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7086 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7087 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7088 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7089 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7090 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 7091 | // can't hook into its internals to cause it to generate predictable NTLM |
| 7092 | // authorization headers. |
| 7093 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7094 | // The NTLM authentication unit tests are based on known test data from the |
| 7095 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 7096 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 7097 | // for the implementation and testing of the protocol. |
| 7098 | // |
| 7099 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7100 | |
| 7101 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7102 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7103 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7104 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7105 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7106 | request.traffic_annotation = |
| 7107 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7108 | |
| 7109 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7110 | // to other auth schemes. |
| 7111 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7112 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7113 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7114 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7115 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7116 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7117 | // Generate the NTLM messages based on known test data. |
| 7118 | std::string negotiate_msg; |
| 7119 | std::string challenge_msg; |
| 7120 | std::string authenticate_msg; |
| 7121 | base::Base64Encode( |
| 7122 | base::StringPiece( |
| 7123 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7124 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7125 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7126 | base::Base64Encode( |
| 7127 | base::StringPiece( |
| 7128 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7129 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7130 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7131 | base::Base64Encode( |
| 7132 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7133 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7134 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7135 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7136 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7137 | &authenticate_msg); |
| 7138 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7139 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7140 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7141 | "Host: server\r\n" |
| 7142 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7143 | }; |
| 7144 | |
| 7145 | MockRead data_reads1[] = { |
| 7146 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7147 | // Negotiate and NTLM are often requested together. However, we only want |
| 7148 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7149 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7150 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7151 | MockRead("Connection: close\r\n"), |
| 7152 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7153 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7154 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7155 | }; |
| 7156 | |
| 7157 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7158 | // After restarting with a null identity, this is the |
| 7159 | // request we should be issuing -- the final header line contains a Type |
| 7160 | // 1 message. |
| 7161 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7162 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7163 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7164 | "Authorization: NTLM "), |
| 7165 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7166 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7167 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7168 | // (using correct credentials). The second request continues on the |
| 7169 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7170 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7171 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7172 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7173 | "Authorization: NTLM "), |
| 7174 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7175 | }; |
| 7176 | |
| 7177 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7178 | // The origin server responds with a Type 2 message. |
| 7179 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7180 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7181 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7182 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7183 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7184 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7185 | // Lastly we get the desired content. |
| 7186 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7187 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7188 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7189 | }; |
| 7190 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7191 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7192 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7193 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7194 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7195 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7196 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7197 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7198 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7199 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7200 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7201 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7202 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7203 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7204 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7205 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7206 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7207 | |
| 7208 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7209 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7210 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7211 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7212 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7213 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7214 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7215 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7216 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7217 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7218 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7219 | rv = trans.RestartWithAuth( |
| 7220 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7221 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7222 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7223 | |
| 7224 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7225 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7226 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7227 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7228 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7229 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7230 | ASSERT_TRUE(response); |
| 7231 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7232 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7233 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7234 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7235 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7236 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7237 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7238 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7239 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7240 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7241 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7242 | ASSERT_TRUE(response); |
| 7243 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7244 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7245 | |
| 7246 | std::string response_data; |
| 7247 | rv = ReadTransaction(&trans, &response_data); |
| 7248 | EXPECT_THAT(rv, IsOk()); |
| 7249 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7250 | |
| 7251 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7252 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7253 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7254 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7255 | } |
| 7256 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7257 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7258 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7259 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7260 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7261 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7262 | request.traffic_annotation = |
| 7263 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7264 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7265 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7266 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7267 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7268 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7269 | // Generate the NTLM messages based on known test data. |
| 7270 | std::string negotiate_msg; |
| 7271 | std::string challenge_msg; |
| 7272 | std::string authenticate_msg; |
| 7273 | base::Base64Encode( |
| 7274 | base::StringPiece( |
| 7275 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7276 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7277 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7278 | base::Base64Encode( |
| 7279 | base::StringPiece( |
| 7280 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7281 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7282 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7283 | base::Base64Encode( |
| 7284 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7285 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7286 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7287 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7288 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7289 | &authenticate_msg); |
| 7290 | |
| 7291 | // The authenticate message when |kWrongPassword| is sent. |
| 7292 | std::string wrong_password_authenticate_msg( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7293 | "TlRMTVNTUAADAAAAGAAYAFgAAACKAIoAcAAAAAwADAD6AAAACAAIAAYBAAAQABAADgEAAAAA" |
| 7294 | "AABYAAAAA4IIAAAAAAAAAAAAAPknEYqtJQtusopDRSfYzAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 7295 | "AAAAAOtVz38osnFdRRggUQHUJ3EBAQAAAAAAAIALyP0A1NIBqqqqqqqqqqoAAAAAAgAMAEQA" |
| 7296 | "bwBtAGEAaQBuAAEADABTAGUAcgB2AGUAcgAGAAQAAgAAAAoAEAAAAAAAAAAAAAAAAAAAAAAA" |
| 7297 | "CQAWAEgAVABUAFAALwBzAGUAcgB2AGUAcgAAAAAAAAAAAEQAbwBtAGEAaQBuAFUAcwBlAHIA" |
| 7298 | "QwBPAE0AUABVAFQARQBSAA=="); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7299 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7300 | // Sanity check that it's the same length as the correct authenticate message |
| 7301 | // and that it's different. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7302 | ASSERT_EQ(authenticate_msg.length(), |
| 7303 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7304 | ASSERT_NE(authenticate_msg, wrong_password_authenticate_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7305 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7306 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7307 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7308 | "Host: server\r\n" |
| 7309 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7310 | }; |
| 7311 | |
| 7312 | MockRead data_reads1[] = { |
| 7313 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7314 | // Negotiate and NTLM are often requested together. However, we only want |
| 7315 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7316 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7317 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7318 | MockRead("Connection: close\r\n"), |
| 7319 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7320 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7321 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7322 | }; |
| 7323 | |
| 7324 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7325 | // After restarting with a null identity, this is the |
| 7326 | // request we should be issuing -- the final header line contains a Type |
| 7327 | // 1 message. |
| 7328 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7329 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7330 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7331 | "Authorization: NTLM "), |
| 7332 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7333 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7334 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7335 | // (using incorrect credentials). The second request continues on the |
| 7336 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7337 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7338 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7339 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7340 | "Authorization: NTLM "), |
| 7341 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7342 | }; |
| 7343 | |
| 7344 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7345 | // The origin server responds with a Type 2 message. |
| 7346 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7347 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7348 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 7349 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7350 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7351 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7352 | // Wrong password. |
| 7353 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7354 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 7355 | MockRead("Content-Length: 42\r\n"), |
| 7356 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7357 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7358 | }; |
| 7359 | |
| 7360 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7361 | // After restarting with a null identity, this is the |
| 7362 | // request we should be issuing -- the final header line contains a Type |
| 7363 | // 1 message. |
| 7364 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7365 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7366 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7367 | "Authorization: NTLM "), |
| 7368 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7369 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7370 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7371 | // (the credentials for the origin server). The second request continues |
| 7372 | // on the same connection. |
| 7373 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7374 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7375 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7376 | "Authorization: NTLM "), |
| 7377 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7378 | }; |
| 7379 | |
| 7380 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7381 | // The origin server responds with a Type 2 message. |
| 7382 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7383 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7384 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7385 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7386 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7387 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7388 | // Lastly we get the desired content. |
| 7389 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7390 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7391 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7392 | }; |
| 7393 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7394 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7395 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7396 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7397 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7398 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7399 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7400 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7401 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7402 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7403 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7404 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7405 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 7406 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 7407 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7408 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7409 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7410 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7411 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7412 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7413 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7414 | |
| 7415 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7416 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7417 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7418 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7419 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7420 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7421 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7422 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7423 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7424 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7425 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7426 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7427 | rv = trans.RestartWithAuth( |
| 7428 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 7429 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7430 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7431 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7432 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7433 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7434 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7435 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7436 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7437 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7438 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7439 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7440 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7441 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7442 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7443 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7444 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7445 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7446 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7447 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7448 | |
| 7449 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7450 | rv = trans.RestartWithAuth( |
| 7451 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7452 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7453 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7454 | |
| 7455 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7456 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7457 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7458 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7459 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7460 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7461 | |
| 7462 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7463 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7464 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7465 | |
| 7466 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7467 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7468 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7469 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7470 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7471 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7472 | |
| 7473 | std::string response_data; |
| 7474 | rv = ReadTransaction(&trans, &response_data); |
| 7475 | EXPECT_THAT(rv, IsOk()); |
| 7476 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7477 | |
| 7478 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7479 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7480 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7481 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 7482 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 7483 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7484 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7485 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7486 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 7487 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7488 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7489 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7490 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7491 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7492 | const char* kUrl = "https://server/kids/login.aspx"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7493 | |
| 7494 | HttpRequestInfo request; |
| 7495 | request.method = "GET"; |
| 7496 | request.url = GURL(kUrl); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7497 | request.traffic_annotation = |
| 7498 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7499 | |
| 7500 | // First request without credentials. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7501 | spdy::SpdyHeaderBlock request_headers0( |
| 7502 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 7503 | spdy::SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7504 | 1, std::move(request_headers0), LOWEST, true)); |
| 7505 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7506 | spdy::SpdyHeaderBlock response_headers0; |
| 7507 | response_headers0[spdy::kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7508 | response_headers0["www-authenticate"] = "NTLM"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7509 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7510 | 1, std::move(response_headers0), true)); |
| 7511 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7512 | // Stream 1 is closed. |
| 7513 | spdy_util_.UpdateWithStreamDestruction(1); |
| 7514 | |
| 7515 | // Generate the NTLM messages based on known test data. |
| 7516 | std::string negotiate_msg; |
| 7517 | std::string challenge_msg; |
| 7518 | std::string authenticate_msg; |
| 7519 | base::Base64Encode( |
| 7520 | base::StringPiece( |
| 7521 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7522 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7523 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7524 | base::Base64Encode( |
| 7525 | base::StringPiece( |
| 7526 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7527 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7528 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7529 | base::Base64Encode( |
| 7530 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7531 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7532 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7533 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7534 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7535 | &authenticate_msg); |
| 7536 | |
| 7537 | // Retry with authorization header. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7538 | spdy::SpdyHeaderBlock request_headers1( |
| 7539 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7540 | request_headers1["authorization"] = std::string("NTLM ") + negotiate_msg; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7541 | spdy::SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7542 | 3, std::move(request_headers1), LOWEST, true)); |
| 7543 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7544 | spdy::SpdySerializedFrame rst( |
| 7545 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_HTTP_1_1_REQUIRED)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7546 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7547 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
| 7548 | MockRead reads0[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7549 | |
| 7550 | // Retry yet again using HTTP/1.1. |
| 7551 | MockWrite writes1[] = { |
| 7552 | // After restarting with a null identity, this is the |
| 7553 | // request we should be issuing -- the final header line contains a Type |
| 7554 | // 1 message. |
| 7555 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7556 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7557 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7558 | "Authorization: NTLM "), |
| 7559 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7560 | |
| 7561 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7562 | // (the credentials for the origin server). The second request continues |
| 7563 | // on the same connection. |
| 7564 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7565 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7566 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7567 | "Authorization: NTLM "), |
| 7568 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7569 | }; |
| 7570 | |
| 7571 | MockRead reads1[] = { |
| 7572 | // The origin server responds with a Type 2 message. |
| 7573 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7574 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7575 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7576 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7577 | MockRead("You are not authorized to view this page\r\n"), |
| 7578 | |
| 7579 | // Lastly we get the desired content. |
| 7580 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7581 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7582 | 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] | 7583 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7584 | SequencedSocketData data0(reads0, writes0); |
| 7585 | StaticSocketDataProvider data1(reads1, writes1); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7586 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 7587 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7588 | |
| 7589 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 7590 | ssl0.next_proto = kProtoHTTP2; |
| 7591 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7592 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 7593 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7594 | |
| 7595 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7596 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7597 | |
| 7598 | TestCompletionCallback callback1; |
| 7599 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 7600 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7601 | |
| 7602 | rv = callback1.WaitForResult(); |
| 7603 | EXPECT_THAT(rv, IsOk()); |
| 7604 | |
| 7605 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7606 | |
| 7607 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7608 | ASSERT_TRUE(response); |
| 7609 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
| 7610 | |
| 7611 | TestCompletionCallback callback2; |
| 7612 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7613 | rv = trans.RestartWithAuth( |
| 7614 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7615 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7616 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7617 | |
| 7618 | rv = callback2.WaitForResult(); |
| 7619 | EXPECT_THAT(rv, IsOk()); |
| 7620 | |
| 7621 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7622 | |
| 7623 | response = trans.GetResponseInfo(); |
| 7624 | ASSERT_TRUE(response); |
| 7625 | EXPECT_FALSE(response->auth_challenge); |
| 7626 | |
| 7627 | TestCompletionCallback callback3; |
| 7628 | |
| 7629 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 7630 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7631 | |
| 7632 | rv = callback3.WaitForResult(); |
| 7633 | EXPECT_THAT(rv, IsOk()); |
| 7634 | |
| 7635 | response = trans.GetResponseInfo(); |
| 7636 | ASSERT_TRUE(response); |
| 7637 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7638 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7639 | |
| 7640 | std::string response_data; |
| 7641 | rv = ReadTransaction(&trans, &response_data); |
| 7642 | EXPECT_THAT(rv, IsOk()); |
| 7643 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7644 | |
| 7645 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 7646 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 7647 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7648 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7649 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7650 | |
| 7651 | // Test that, if we have an NTLM proxy and the origin resets the connection, we |
| 7652 | // do no retry forever checking for TLS version interference. This is a |
| 7653 | // regression test for https://crbug.com/823387. |
| 7654 | TEST_F(HttpNetworkTransactionTest, NTLMProxyTLSHandshakeReset) { |
| 7655 | // The NTLM test data expects the proxy to be named 'server'. The origin is |
| 7656 | // https://origin/. |
| 7657 | session_deps_.proxy_resolution_service = |
| 7658 | ProxyResolutionService::CreateFixedFromPacResult( |
| 7659 | "PROXY server", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7660 | |
| 7661 | SSLConfig config; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7662 | session_deps_.ssl_config_service = |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 7663 | std::make_unique<TestSSLConfigService>(config); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7664 | |
| 7665 | HttpRequestInfo request; |
| 7666 | request.method = "GET"; |
| 7667 | request.url = GURL("https://origin/"); |
| 7668 | request.traffic_annotation = |
| 7669 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7670 | |
| 7671 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7672 | // to other auth schemes. |
| 7673 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 7674 | |
| 7675 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7676 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
| 7677 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7678 | |
| 7679 | // Generate the NTLM messages based on known test data. |
| 7680 | std::string negotiate_msg; |
| 7681 | std::string challenge_msg; |
| 7682 | std::string authenticate_msg; |
| 7683 | base::Base64Encode( |
| 7684 | base::StringPiece( |
| 7685 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7686 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7687 | &negotiate_msg); |
| 7688 | base::Base64Encode( |
| 7689 | base::StringPiece( |
| 7690 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7691 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7692 | &challenge_msg); |
| 7693 | base::Base64Encode( |
| 7694 | base::StringPiece( |
| 7695 | reinterpret_cast<const char*>( |
| 7696 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7697 | base::size( |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7698 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
| 7699 | &authenticate_msg); |
| 7700 | |
| 7701 | MockWrite data_writes[] = { |
| 7702 | // The initial CONNECT request. |
| 7703 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7704 | "Host: origin:443\r\n" |
| 7705 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7706 | |
| 7707 | // After restarting with an identity. |
| 7708 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7709 | "Host: origin:443\r\n" |
| 7710 | "Proxy-Connection: keep-alive\r\n" |
| 7711 | "Proxy-Authorization: NTLM "), |
| 7712 | MockWrite(negotiate_msg.c_str()), |
| 7713 | // End headers. |
| 7714 | MockWrite("\r\n\r\n"), |
| 7715 | |
| 7716 | // The second restart. |
| 7717 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7718 | "Host: origin:443\r\n" |
| 7719 | "Proxy-Connection: keep-alive\r\n" |
| 7720 | "Proxy-Authorization: NTLM "), |
| 7721 | MockWrite(authenticate_msg.c_str()), |
| 7722 | // End headers. |
| 7723 | MockWrite("\r\n\r\n"), |
| 7724 | }; |
| 7725 | |
| 7726 | MockRead data_reads[] = { |
| 7727 | // The initial NTLM response. |
| 7728 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7729 | "Content-Length: 0\r\n" |
| 7730 | "Proxy-Authenticate: NTLM\r\n\r\n"), |
| 7731 | |
| 7732 | // The NTLM challenge message. |
| 7733 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7734 | "Content-Length: 0\r\n" |
| 7735 | "Proxy-Authenticate: NTLM "), |
| 7736 | MockRead(challenge_msg.c_str()), |
| 7737 | // End headers. |
| 7738 | MockRead("\r\n\r\n"), |
| 7739 | |
| 7740 | // Finally the tunnel is established. |
| 7741 | MockRead("HTTP/1.1 200 Connected\r\n\r\n"), |
| 7742 | }; |
| 7743 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7744 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7745 | SSLSocketDataProvider data_ssl(ASYNC, ERR_CONNECTION_RESET); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7746 | StaticSocketDataProvider data2(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7747 | SSLSocketDataProvider data_ssl2(ASYNC, ERR_CONNECTION_RESET); |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 7748 | data_ssl2.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7749 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7750 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl); |
| 7751 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7752 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl2); |
| 7753 | |
| 7754 | // Start the transaction. The proxy responds with an NTLM authentication |
| 7755 | // request. |
| 7756 | TestCompletionCallback callback; |
| 7757 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7758 | int rv = callback.GetResult( |
| 7759 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 7760 | |
| 7761 | EXPECT_THAT(rv, IsOk()); |
| 7762 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7763 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7764 | ASSERT_TRUE(response); |
| 7765 | EXPECT_TRUE(CheckNTLMProxyAuth(response->auth_challenge.get())); |
| 7766 | |
| 7767 | // Configure credentials. The proxy responds with the challenge message. |
| 7768 | rv = callback.GetResult(trans.RestartWithAuth( |
| 7769 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7770 | callback.callback())); |
| 7771 | EXPECT_THAT(rv, IsOk()); |
| 7772 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7773 | response = trans.GetResponseInfo(); |
| 7774 | ASSERT_TRUE(response); |
| 7775 | EXPECT_FALSE(response->auth_challenge); |
| 7776 | |
| 7777 | // Restart once more. The tunnel will be established and the the SSL handshake |
| 7778 | // will reset. The TLS 1.3 version interference probe will then kick in and |
| 7779 | // restart the process. The proxy responds with another NTLM authentiation |
| 7780 | // request, but we don't need to provide credentials as the cached ones work/ |
| 7781 | rv = callback.GetResult( |
| 7782 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7783 | EXPECT_THAT(rv, IsOk()); |
| 7784 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7785 | response = trans.GetResponseInfo(); |
| 7786 | ASSERT_TRUE(response); |
| 7787 | EXPECT_FALSE(response->auth_challenge); |
| 7788 | |
| 7789 | // The proxy responds with the NTLM challenge message. |
| 7790 | rv = callback.GetResult( |
| 7791 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7792 | EXPECT_THAT(rv, IsOk()); |
| 7793 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7794 | response = trans.GetResponseInfo(); |
| 7795 | ASSERT_TRUE(response); |
| 7796 | EXPECT_FALSE(response->auth_challenge); |
| 7797 | |
| 7798 | // Send the NTLM authenticate message. The tunnel is established and the |
| 7799 | // handshake resets again. We should not retry again. |
| 7800 | rv = callback.GetResult( |
| 7801 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7802 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
| 7803 | } |
| 7804 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7805 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7806 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7807 | // Test reading a server response which has only headers, and no body. |
| 7808 | // After some maximum number of bytes is consumed, the transaction should |
| 7809 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7810 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7811 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7812 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7813 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7814 | request.traffic_annotation = |
| 7815 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7816 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7817 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7818 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7819 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7820 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 7821 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7822 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7823 | |
| 7824 | MockRead data_reads[] = { |
| 7825 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7826 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7827 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7828 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7829 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7830 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7831 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7832 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7833 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7834 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7835 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7836 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7837 | |
| 7838 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7839 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7840 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7841 | |
| 7842 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 7843 | // establish tunnel. |
| 7844 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7845 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7846 | HttpRequestInfo request; |
| 7847 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7848 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7849 | request.traffic_annotation = |
| 7850 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7851 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7852 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 7853 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 7854 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 7855 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7856 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7857 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7858 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7859 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7860 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7861 | // Since we have proxy, should try to establish tunnel. |
| 7862 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7863 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7864 | "Host: www.example.org:443\r\n" |
| 7865 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7866 | }; |
| 7867 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7868 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7869 | // connection. Usually a proxy would return 501 (not implemented), |
| 7870 | // or 200 (tunnel established). |
| 7871 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 7872 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7873 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7874 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7875 | }; |
| 7876 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7877 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7878 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7879 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7880 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7881 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7882 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7883 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7884 | |
| 7885 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7886 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7887 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7888 | // Empty the current queue. This is necessary because idle sockets are |
| 7889 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7890 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7891 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7892 | // We now check to make sure the TCPClientSocket was not added back to |
| 7893 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7894 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7895 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7896 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7897 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7898 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7899 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7900 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7901 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7902 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7903 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7904 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7905 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7906 | request.traffic_annotation = |
| 7907 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7908 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7909 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7910 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7911 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7912 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7913 | MockRead data_reads[] = { |
| 7914 | // A part of the response body is received with the response headers. |
| 7915 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7916 | // The rest of the response body is received in two parts. |
| 7917 | MockRead("lo"), |
| 7918 | MockRead(" world"), |
| 7919 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7920 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7921 | }; |
| 7922 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7923 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7924 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7925 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7926 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7927 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7928 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7929 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7930 | |
| 7931 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7932 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7933 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7934 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7935 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7936 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7937 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7938 | std::string status_line = response->headers->GetStatusLine(); |
| 7939 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7940 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7941 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7942 | |
| 7943 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7944 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7945 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7946 | EXPECT_EQ("hello world", response_data); |
| 7947 | |
| 7948 | // Empty the current queue. This is necessary because idle sockets are |
| 7949 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7950 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7951 | |
| 7952 | // 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] | 7953 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7954 | } |
| 7955 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7956 | // Make sure that we recycle a SSL socket after reading all of the response |
| 7957 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7958 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7959 | HttpRequestInfo request; |
| 7960 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7961 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7962 | request.traffic_annotation = |
| 7963 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7964 | |
| 7965 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7966 | MockWrite( |
| 7967 | "GET / HTTP/1.1\r\n" |
| 7968 | "Host: www.example.org\r\n" |
| 7969 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7970 | }; |
| 7971 | |
| 7972 | MockRead data_reads[] = { |
| 7973 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7974 | MockRead("Content-Length: 11\r\n\r\n"), |
| 7975 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7976 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7977 | }; |
| 7978 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7979 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7980 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7981 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7982 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7983 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7984 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7985 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7986 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7987 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7988 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7989 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7990 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7991 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7992 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7993 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7994 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7995 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7996 | ASSERT_TRUE(response); |
| 7997 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7998 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7999 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8000 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8001 | |
| 8002 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8003 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8004 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8005 | EXPECT_EQ("hello world", response_data); |
| 8006 | |
| 8007 | // Empty the current queue. This is necessary because idle sockets are |
| 8008 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8009 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8010 | |
| 8011 | // 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] | 8012 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8013 | } |
| 8014 | |
| 8015 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 8016 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8017 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8018 | HttpRequestInfo request; |
| 8019 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8020 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8021 | request.traffic_annotation = |
| 8022 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8023 | |
| 8024 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8025 | MockWrite( |
| 8026 | "GET / HTTP/1.1\r\n" |
| 8027 | "Host: www.example.org\r\n" |
| 8028 | "Connection: keep-alive\r\n\r\n"), |
| 8029 | MockWrite( |
| 8030 | "GET / HTTP/1.1\r\n" |
| 8031 | "Host: www.example.org\r\n" |
| 8032 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8033 | }; |
| 8034 | |
| 8035 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 8036 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8037 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8038 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8039 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8040 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8041 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8042 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8043 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8044 | StaticSocketDataProvider data(data_reads, data_writes); |
| 8045 | StaticSocketDataProvider data2(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8046 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8047 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8048 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8049 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8050 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8051 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8052 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8053 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8054 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8055 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8056 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8057 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8058 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8059 | |
| 8060 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8061 | ASSERT_TRUE(response); |
| 8062 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8063 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8064 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8065 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8066 | |
| 8067 | std::string response_data; |
| 8068 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8069 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8070 | EXPECT_EQ("hello world", response_data); |
| 8071 | |
| 8072 | // Empty the current queue. This is necessary because idle sockets are |
| 8073 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8074 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8075 | |
| 8076 | // 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] | 8077 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8078 | |
| 8079 | // Now start the second transaction, which should reuse the previous socket. |
| 8080 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8081 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8082 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8083 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8084 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8085 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8086 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8087 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8088 | |
| 8089 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8090 | ASSERT_TRUE(response); |
| 8091 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8092 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8093 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8094 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8095 | |
| 8096 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8097 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8098 | EXPECT_EQ("hello world", response_data); |
| 8099 | |
| 8100 | // Empty the current queue. This is necessary because idle sockets are |
| 8101 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8102 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8103 | |
| 8104 | // 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] | 8105 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8106 | } |
| 8107 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8108 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8109 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8110 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8111 | HttpRequestInfo request; |
| 8112 | request.method = "GET"; |
| 8113 | request.url = GURL("http://www.example.org/"); |
| 8114 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8115 | request.traffic_annotation = |
| 8116 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8117 | |
| 8118 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8119 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8120 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8121 | |
| 8122 | MockRead data_reads[] = { |
| 8123 | // A part of the response body is received with the response headers. |
| 8124 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8125 | // The rest of the response body is received in two parts. |
| 8126 | MockRead("lo"), MockRead(" world"), |
| 8127 | MockRead("junk"), // Should not be read!! |
| 8128 | MockRead(SYNCHRONOUS, OK), |
| 8129 | }; |
| 8130 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8131 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8132 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8133 | |
| 8134 | TestCompletionCallback callback; |
| 8135 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8136 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8137 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8138 | |
| 8139 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8140 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8141 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8142 | ASSERT_TRUE(response); |
| 8143 | EXPECT_TRUE(response->headers); |
| 8144 | std::string status_line = response->headers->GetStatusLine(); |
| 8145 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8146 | |
| 8147 | // Make memory critical notification and ensure the transaction still has been |
| 8148 | // operating right. |
| 8149 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8150 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8151 | base::RunLoop().RunUntilIdle(); |
| 8152 | |
| 8153 | // Socket should not be flushed as long as it is not idle. |
| 8154 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8155 | |
| 8156 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8157 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8158 | EXPECT_THAT(rv, IsOk()); |
| 8159 | EXPECT_EQ("hello world", response_data); |
| 8160 | |
| 8161 | // Empty the current queue. This is necessary because idle sockets are |
| 8162 | // added to the connection pool asynchronously with a PostTask. |
| 8163 | base::RunLoop().RunUntilIdle(); |
| 8164 | |
| 8165 | // We now check to make sure the socket was added back to the pool. |
| 8166 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8167 | |
| 8168 | // Idle sockets should be flushed now. |
| 8169 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8170 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8171 | base::RunLoop().RunUntilIdle(); |
| 8172 | |
| 8173 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8174 | } |
| 8175 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8176 | // Disable idle socket closing on memory pressure. |
| 8177 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8178 | // low memory notification and ensure the socket pool is NOT flushed. |
| 8179 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 8180 | HttpRequestInfo request; |
| 8181 | request.method = "GET"; |
| 8182 | request.url = GURL("http://www.example.org/"); |
| 8183 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8184 | request.traffic_annotation = |
| 8185 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8186 | |
| 8187 | // Disable idle socket closing on memory pressure. |
| 8188 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 8189 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8190 | |
| 8191 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 8192 | |
| 8193 | MockRead data_reads[] = { |
| 8194 | // A part of the response body is received with the response headers. |
| 8195 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8196 | // The rest of the response body is received in two parts. |
| 8197 | MockRead("lo"), MockRead(" world"), |
| 8198 | MockRead("junk"), // Should not be read!! |
| 8199 | MockRead(SYNCHRONOUS, OK), |
| 8200 | }; |
| 8201 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8202 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8203 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8204 | |
| 8205 | TestCompletionCallback callback; |
| 8206 | |
| 8207 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 8208 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8209 | |
| 8210 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8211 | |
| 8212 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 8213 | ASSERT_TRUE(response); |
| 8214 | EXPECT_TRUE(response->headers); |
| 8215 | std::string status_line = response->headers->GetStatusLine(); |
| 8216 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8217 | |
| 8218 | // Make memory critical notification and ensure the transaction still has been |
| 8219 | // operating right. |
| 8220 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8221 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8222 | base::RunLoop().RunUntilIdle(); |
| 8223 | |
| 8224 | // Socket should not be flushed as long as it is not idle. |
| 8225 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8226 | |
| 8227 | std::string response_data; |
| 8228 | rv = ReadTransaction(&trans, &response_data); |
| 8229 | EXPECT_THAT(rv, IsOk()); |
| 8230 | EXPECT_EQ("hello world", response_data); |
| 8231 | |
| 8232 | // Empty the current queue. This is necessary because idle sockets are |
| 8233 | // added to the connection pool asynchronously with a PostTask. |
| 8234 | base::RunLoop().RunUntilIdle(); |
| 8235 | |
| 8236 | // We now check to make sure the socket was added back to the pool. |
| 8237 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8238 | |
| 8239 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 8240 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8241 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 8242 | base::RunLoop().RunUntilIdle(); |
| 8243 | |
| 8244 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8245 | |
| 8246 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 8247 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8248 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8249 | base::RunLoop().RunUntilIdle(); |
| 8250 | |
| 8251 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8252 | } |
| 8253 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8254 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 8255 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8256 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8257 | HttpRequestInfo request; |
| 8258 | request.method = "GET"; |
| 8259 | request.url = GURL("https://www.example.org/"); |
| 8260 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8261 | request.traffic_annotation = |
| 8262 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8263 | |
| 8264 | MockWrite data_writes[] = { |
| 8265 | MockWrite("GET / HTTP/1.1\r\n" |
| 8266 | "Host: www.example.org\r\n" |
| 8267 | "Connection: keep-alive\r\n\r\n"), |
| 8268 | }; |
| 8269 | |
| 8270 | MockRead data_reads[] = { |
| 8271 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8272 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 8273 | |
| 8274 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8275 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8276 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8277 | StaticSocketDataProvider data(data_reads, data_writes); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8278 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8279 | |
| 8280 | TestCompletionCallback callback; |
| 8281 | |
| 8282 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8283 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8284 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8285 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8286 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8287 | |
| 8288 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8289 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8290 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8291 | ASSERT_TRUE(response); |
| 8292 | ASSERT_TRUE(response->headers); |
| 8293 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8294 | |
| 8295 | // Make memory critical notification and ensure the transaction still has been |
| 8296 | // operating right. |
| 8297 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8298 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8299 | base::RunLoop().RunUntilIdle(); |
| 8300 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8301 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8302 | |
| 8303 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8304 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8305 | EXPECT_THAT(rv, IsOk()); |
| 8306 | EXPECT_EQ("hello world", response_data); |
| 8307 | |
| 8308 | // Empty the current queue. This is necessary because idle sockets are |
| 8309 | // added to the connection pool asynchronously with a PostTask. |
| 8310 | base::RunLoop().RunUntilIdle(); |
| 8311 | |
| 8312 | // 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] | 8313 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8314 | |
| 8315 | // Make memory notification once again and ensure idle socket is closed. |
| 8316 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8317 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8318 | base::RunLoop().RunUntilIdle(); |
| 8319 | |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 8320 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8321 | } |
| 8322 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8323 | // Make sure that we recycle a socket after a zero-length response. |
| 8324 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8325 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8326 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8327 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8328 | request.url = GURL( |
| 8329 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 8330 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 8331 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 8332 | "rt=prt.2642,ol.2649,xjs.2951"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8333 | request.traffic_annotation = |
| 8334 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8335 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8336 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8337 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8338 | MockRead data_reads[] = { |
| 8339 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 8340 | "Content-Length: 0\r\n" |
| 8341 | "Content-Type: text/html\r\n\r\n"), |
| 8342 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8343 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8344 | }; |
| 8345 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8346 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8347 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8348 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8349 | // Transaction must be created after the MockReads, so it's destroyed before |
| 8350 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8351 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8352 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8353 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8354 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8355 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8356 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8357 | |
| 8358 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8359 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8360 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8361 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8362 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8363 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8364 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8365 | std::string status_line = response->headers->GetStatusLine(); |
| 8366 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 8367 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8368 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8369 | |
| 8370 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8371 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8372 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8373 | EXPECT_EQ("", response_data); |
| 8374 | |
| 8375 | // Empty the current queue. This is necessary because idle sockets are |
| 8376 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8377 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8378 | |
| 8379 | // 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] | 8380 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8381 | } |
| 8382 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8383 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8384 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8385 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8386 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8387 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8388 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8389 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8390 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 8391 | // after use. |
| 8392 | request[0].method = "GET"; |
| 8393 | request[0].url = GURL("http://www.google.com/"); |
| 8394 | request[0].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8395 | request[0].traffic_annotation = |
| 8396 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8397 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 8398 | // transaction 1. The first attempts fails when writing the POST data. |
| 8399 | // This causes the transaction to retry with a new socket. The second |
| 8400 | // attempt succeeds. |
| 8401 | request[1].method = "POST"; |
| 8402 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8403 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8404 | request[1].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8405 | request[1].traffic_annotation = |
| 8406 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8407 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8408 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8409 | |
| 8410 | // The first socket is used for transaction 1 and the first attempt of |
| 8411 | // transaction 2. |
| 8412 | |
| 8413 | // The response of transaction 1. |
| 8414 | MockRead data_reads1[] = { |
| 8415 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 8416 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8417 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8418 | }; |
| 8419 | // The mock write results of transaction 1 and the first attempt of |
| 8420 | // transaction 2. |
| 8421 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8422 | MockWrite(SYNCHRONOUS, 64), // GET |
| 8423 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8424 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8425 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8426 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8427 | |
| 8428 | // The second socket is used for the second attempt of transaction 2. |
| 8429 | |
| 8430 | // The response of transaction 2. |
| 8431 | MockRead data_reads2[] = { |
| 8432 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 8433 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8434 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8435 | }; |
| 8436 | // The mock write results of the second attempt of transaction 2. |
| 8437 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8438 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8439 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8440 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8441 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8442 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8443 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8444 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8445 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8446 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8447 | "hello world", "welcome" |
| 8448 | }; |
| 8449 | |
| 8450 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8451 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8452 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8453 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8454 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8455 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8456 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8457 | |
| 8458 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8459 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8460 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8461 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8462 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8463 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8464 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8465 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8466 | |
| 8467 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8468 | rv = ReadTransaction(&trans, &response_data); |
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 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 8471 | } |
| 8472 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8473 | |
| 8474 | // Test the request-challenge-retry sequence for basic auth when there is |
| 8475 | // 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] | 8476 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8477 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8478 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8479 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8480 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 8481 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8482 | request.traffic_annotation = |
| 8483 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8484 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8485 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8486 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8487 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8488 | // The password contains an escaped character -- for this test to pass it |
| 8489 | // will need to be unescaped by HttpNetworkTransaction. |
| 8490 | EXPECT_EQ("b%40r", request.url.password()); |
| 8491 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8492 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8493 | MockWrite( |
| 8494 | "GET / HTTP/1.1\r\n" |
| 8495 | "Host: www.example.org\r\n" |
| 8496 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8497 | }; |
| 8498 | |
| 8499 | MockRead data_reads1[] = { |
| 8500 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8501 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8502 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8503 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8504 | }; |
| 8505 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8506 | // After the challenge above, the transaction will be restarted using the |
| 8507 | // identity from the url (foo, b@r) to answer the challenge. |
| 8508 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8509 | MockWrite( |
| 8510 | "GET / HTTP/1.1\r\n" |
| 8511 | "Host: www.example.org\r\n" |
| 8512 | "Connection: keep-alive\r\n" |
| 8513 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8514 | }; |
| 8515 | |
| 8516 | MockRead data_reads2[] = { |
| 8517 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8518 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8519 | MockRead(SYNCHRONOUS, OK), |
| 8520 | }; |
| 8521 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8522 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8523 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8524 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8525 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8526 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8527 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8528 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8529 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8530 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8531 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8532 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8533 | |
| 8534 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8535 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8536 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8537 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8538 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8539 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8540 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8541 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8542 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8543 | |
| 8544 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8545 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8546 | |
| 8547 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8548 | |
| 8549 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8550 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8551 | } |
| 8552 | |
| 8553 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 8554 | // incorrect identity in the URL. The identity from the URL should be used only |
| 8555 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8556 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8557 | HttpRequestInfo request; |
| 8558 | request.method = "GET"; |
| 8559 | // Note: the URL has a username:password in it. The password "baz" is |
| 8560 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8561 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8562 | |
| 8563 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8564 | request.traffic_annotation = |
| 8565 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8566 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8567 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8568 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8569 | |
| 8570 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8571 | MockWrite( |
| 8572 | "GET / HTTP/1.1\r\n" |
| 8573 | "Host: www.example.org\r\n" |
| 8574 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8575 | }; |
| 8576 | |
| 8577 | MockRead data_reads1[] = { |
| 8578 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8579 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8580 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8581 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8582 | }; |
| 8583 | |
| 8584 | // After the challenge above, the transaction will be restarted using the |
| 8585 | // identity from the url (foo, baz) to answer the challenge. |
| 8586 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8587 | MockWrite( |
| 8588 | "GET / HTTP/1.1\r\n" |
| 8589 | "Host: www.example.org\r\n" |
| 8590 | "Connection: keep-alive\r\n" |
| 8591 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8592 | }; |
| 8593 | |
| 8594 | MockRead data_reads2[] = { |
| 8595 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8596 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8597 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8598 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8599 | }; |
| 8600 | |
| 8601 | // After the challenge above, the transaction will be restarted using the |
| 8602 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 8603 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8604 | MockWrite( |
| 8605 | "GET / HTTP/1.1\r\n" |
| 8606 | "Host: www.example.org\r\n" |
| 8607 | "Connection: keep-alive\r\n" |
| 8608 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8609 | }; |
| 8610 | |
| 8611 | MockRead data_reads3[] = { |
| 8612 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8613 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8614 | MockRead(SYNCHRONOUS, OK), |
| 8615 | }; |
| 8616 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8617 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8618 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 8619 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8620 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8621 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8622 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8623 | |
| 8624 | TestCompletionCallback callback1; |
| 8625 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8626 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8627 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8628 | |
| 8629 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8630 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8631 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8632 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8633 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8634 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8635 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8636 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8637 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8638 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8639 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8640 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8641 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8642 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 8643 | |
| 8644 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8645 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8646 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8647 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8648 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8649 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8650 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8651 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8652 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8653 | |
| 8654 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8655 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8656 | |
| 8657 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8658 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8659 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8660 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8661 | } |
| 8662 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8663 | |
| 8664 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 8665 | // correct identity in the URL, but its use is being suppressed. The identity |
| 8666 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8667 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8668 | HttpRequestInfo request; |
| 8669 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8670 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8671 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8672 | request.traffic_annotation = |
| 8673 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8674 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8675 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8676 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8677 | |
| 8678 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8679 | MockWrite( |
| 8680 | "GET / HTTP/1.1\r\n" |
| 8681 | "Host: www.example.org\r\n" |
| 8682 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8683 | }; |
| 8684 | |
| 8685 | MockRead data_reads1[] = { |
| 8686 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8687 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8688 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8689 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8690 | }; |
| 8691 | |
| 8692 | // After the challenge above, the transaction will be restarted using the |
| 8693 | // identity supplied by the user, not the one in the URL, to answer the |
| 8694 | // challenge. |
| 8695 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8696 | MockWrite( |
| 8697 | "GET / HTTP/1.1\r\n" |
| 8698 | "Host: www.example.org\r\n" |
| 8699 | "Connection: keep-alive\r\n" |
| 8700 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8701 | }; |
| 8702 | |
| 8703 | MockRead data_reads3[] = { |
| 8704 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8705 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8706 | MockRead(SYNCHRONOUS, OK), |
| 8707 | }; |
| 8708 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8709 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8710 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8711 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8712 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 8713 | |
| 8714 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8715 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8716 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8717 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8718 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8719 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8720 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8721 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8722 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8723 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 8724 | |
| 8725 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8726 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8727 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8728 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8729 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8730 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8731 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8732 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8733 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8734 | |
| 8735 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8736 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8737 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8738 | |
| 8739 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8740 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8741 | } |
| 8742 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8743 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8744 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8745 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8746 | |
| 8747 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8748 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8749 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8750 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8751 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8752 | request.traffic_annotation = |
| 8753 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8754 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8755 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8756 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8757 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8758 | MockWrite( |
| 8759 | "GET /x/y/z HTTP/1.1\r\n" |
| 8760 | "Host: www.example.org\r\n" |
| 8761 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8762 | }; |
| 8763 | |
| 8764 | MockRead data_reads1[] = { |
| 8765 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8766 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8767 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8768 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8769 | }; |
| 8770 | |
| 8771 | // Resend with authorization (username=foo, password=bar) |
| 8772 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8773 | MockWrite( |
| 8774 | "GET /x/y/z HTTP/1.1\r\n" |
| 8775 | "Host: www.example.org\r\n" |
| 8776 | "Connection: keep-alive\r\n" |
| 8777 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8778 | }; |
| 8779 | |
| 8780 | // Sever accepts the authorization. |
| 8781 | MockRead data_reads2[] = { |
| 8782 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8783 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8784 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8785 | }; |
| 8786 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8787 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8788 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8789 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8790 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8791 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8792 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8793 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8794 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8795 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8796 | |
| 8797 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8798 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8799 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8800 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8801 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8802 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8803 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8804 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8805 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8806 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8807 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8808 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8809 | |
| 8810 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8811 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8812 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8813 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8814 | ASSERT_TRUE(response); |
| 8815 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8816 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8817 | } |
| 8818 | |
| 8819 | // ------------------------------------------------------------------------ |
| 8820 | |
| 8821 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 8822 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8823 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8824 | request.method = "GET"; |
| 8825 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8826 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8827 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8828 | request.traffic_annotation = |
| 8829 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8830 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8831 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8832 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8833 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8834 | MockWrite( |
| 8835 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8836 | "Host: www.example.org\r\n" |
| 8837 | "Connection: keep-alive\r\n" |
| 8838 | // Send preemptive authorization for MyRealm1 |
| 8839 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8840 | }; |
| 8841 | |
| 8842 | // The server didn't like the preemptive authorization, and |
| 8843 | // challenges us for a different realm (MyRealm2). |
| 8844 | MockRead data_reads1[] = { |
| 8845 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8846 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 8847 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8848 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8849 | }; |
| 8850 | |
| 8851 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 8852 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8853 | MockWrite( |
| 8854 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8855 | "Host: www.example.org\r\n" |
| 8856 | "Connection: keep-alive\r\n" |
| 8857 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8858 | }; |
| 8859 | |
| 8860 | // Sever accepts the authorization. |
| 8861 | MockRead data_reads2[] = { |
| 8862 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8863 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8864 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8865 | }; |
| 8866 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8867 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8868 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8869 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8870 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8871 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8872 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8873 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8874 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8875 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8876 | |
| 8877 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8878 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8879 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8880 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8881 | ASSERT_TRUE(response); |
| 8882 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8883 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8884 | EXPECT_EQ("http://www.example.org", |
| 8885 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8886 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 8887 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8888 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8889 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8890 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8891 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 8892 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8893 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8894 | |
| 8895 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8896 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8897 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8898 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8899 | ASSERT_TRUE(response); |
| 8900 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8901 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8902 | } |
| 8903 | |
| 8904 | // ------------------------------------------------------------------------ |
| 8905 | |
| 8906 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 8907 | // succeed with preemptive authorization. |
| 8908 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8909 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8910 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8911 | request.url = GURL("http://www.example.org/x/y/z2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8912 | request.traffic_annotation = |
| 8913 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8914 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8915 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8916 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8917 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8918 | MockWrite( |
| 8919 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 8920 | "Host: www.example.org\r\n" |
| 8921 | "Connection: keep-alive\r\n" |
| 8922 | // The authorization for MyRealm1 gets sent preemptively |
| 8923 | // (since the url is in the same protection space) |
| 8924 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8925 | }; |
| 8926 | |
| 8927 | // Sever accepts the preemptive authorization |
| 8928 | MockRead data_reads1[] = { |
| 8929 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8930 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8931 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8932 | }; |
| 8933 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8934 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8935 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8936 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8937 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8938 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8939 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8940 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8941 | |
| 8942 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8943 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8944 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8945 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8946 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8947 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8948 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8949 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8950 | } |
| 8951 | |
| 8952 | // ------------------------------------------------------------------------ |
| 8953 | |
| 8954 | // Transaction 4: request another URL in MyRealm (however the |
| 8955 | // url is not known to belong to the protection space, so no pre-auth). |
| 8956 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8957 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8958 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8959 | request.url = GURL("http://www.example.org/x/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8960 | request.traffic_annotation = |
| 8961 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8962 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8963 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8964 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8965 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8966 | MockWrite( |
| 8967 | "GET /x/1 HTTP/1.1\r\n" |
| 8968 | "Host: www.example.org\r\n" |
| 8969 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8970 | }; |
| 8971 | |
| 8972 | MockRead data_reads1[] = { |
| 8973 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8974 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8975 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8976 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8977 | }; |
| 8978 | |
| 8979 | // Resend with authorization from MyRealm's cache. |
| 8980 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8981 | MockWrite( |
| 8982 | "GET /x/1 HTTP/1.1\r\n" |
| 8983 | "Host: www.example.org\r\n" |
| 8984 | "Connection: keep-alive\r\n" |
| 8985 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8986 | }; |
| 8987 | |
| 8988 | // Sever accepts the authorization. |
| 8989 | MockRead data_reads2[] = { |
| 8990 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8991 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8992 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8993 | }; |
| 8994 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8995 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8996 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8997 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8998 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8999 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9000 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9001 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9002 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9003 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9004 | |
| 9005 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9006 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9007 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9008 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9009 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9010 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9011 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9012 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9013 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9014 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9015 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9016 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9017 | ASSERT_TRUE(response); |
| 9018 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9019 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9020 | } |
| 9021 | |
| 9022 | // ------------------------------------------------------------------------ |
| 9023 | |
| 9024 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 9025 | // cached identity. Should invalidate and re-prompt. |
| 9026 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9027 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9028 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9029 | request.url = GURL("http://www.example.org/p/q/t"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9030 | request.traffic_annotation = |
| 9031 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9032 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9033 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9034 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9035 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9036 | MockWrite( |
| 9037 | "GET /p/q/t HTTP/1.1\r\n" |
| 9038 | "Host: www.example.org\r\n" |
| 9039 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9040 | }; |
| 9041 | |
| 9042 | MockRead data_reads1[] = { |
| 9043 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9044 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9045 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9046 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9047 | }; |
| 9048 | |
| 9049 | // Resend with authorization from cache for MyRealm. |
| 9050 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9051 | MockWrite( |
| 9052 | "GET /p/q/t HTTP/1.1\r\n" |
| 9053 | "Host: www.example.org\r\n" |
| 9054 | "Connection: keep-alive\r\n" |
| 9055 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9056 | }; |
| 9057 | |
| 9058 | // Sever rejects the authorization. |
| 9059 | MockRead data_reads2[] = { |
| 9060 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9061 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9062 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9063 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9064 | }; |
| 9065 | |
| 9066 | // At this point we should prompt for new credentials for MyRealm. |
| 9067 | // Restart with username=foo3, password=foo4. |
| 9068 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9069 | MockWrite( |
| 9070 | "GET /p/q/t HTTP/1.1\r\n" |
| 9071 | "Host: www.example.org\r\n" |
| 9072 | "Connection: keep-alive\r\n" |
| 9073 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9074 | }; |
| 9075 | |
| 9076 | // Sever accepts the authorization. |
| 9077 | MockRead data_reads3[] = { |
| 9078 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9079 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9080 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9081 | }; |
| 9082 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9083 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9084 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 9085 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9086 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9087 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9088 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9089 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9090 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9091 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9092 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9093 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9094 | |
| 9095 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9096 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9097 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9098 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9099 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9100 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9101 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9102 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9103 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9104 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9105 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9106 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9107 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9108 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9109 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9110 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9111 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9112 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 9113 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9114 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9115 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9116 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9117 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9118 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9119 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9120 | ASSERT_TRUE(response); |
| 9121 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9122 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9123 | } |
| 9124 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9125 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9126 | // Tests that nonce count increments when multiple auth attempts |
| 9127 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9128 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 9129 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 9130 | new HttpAuthHandlerDigest::Factory(); |
| 9131 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 9132 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 9133 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9134 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9135 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9136 | |
| 9137 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 9138 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9139 | HttpRequestInfo request; |
| 9140 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9141 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9142 | request.traffic_annotation = |
| 9143 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9144 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9145 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9146 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9147 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9148 | MockWrite( |
| 9149 | "GET /x/y/z HTTP/1.1\r\n" |
| 9150 | "Host: www.example.org\r\n" |
| 9151 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9152 | }; |
| 9153 | |
| 9154 | MockRead data_reads1[] = { |
| 9155 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9156 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 9157 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9158 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9159 | }; |
| 9160 | |
| 9161 | // Resend with authorization (username=foo, password=bar) |
| 9162 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9163 | MockWrite( |
| 9164 | "GET /x/y/z HTTP/1.1\r\n" |
| 9165 | "Host: www.example.org\r\n" |
| 9166 | "Connection: keep-alive\r\n" |
| 9167 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9168 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 9169 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 9170 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9171 | }; |
| 9172 | |
| 9173 | // Sever accepts the authorization. |
| 9174 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9175 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9176 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9177 | }; |
| 9178 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9179 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9180 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9181 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9182 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9183 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9184 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9185 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9186 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9187 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9188 | |
| 9189 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9190 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9191 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9192 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9193 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9194 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9195 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9196 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9197 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9198 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9199 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9200 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9201 | |
| 9202 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9203 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9204 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9205 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9206 | ASSERT_TRUE(response); |
| 9207 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9208 | } |
| 9209 | |
| 9210 | // ------------------------------------------------------------------------ |
| 9211 | |
| 9212 | // Transaction 2: Request another resource in digestive's protection space. |
| 9213 | // This will preemptively add an Authorization header which should have an |
| 9214 | // "nc" value of 2 (as compared to 1 in the first use. |
| 9215 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9216 | HttpRequestInfo request; |
| 9217 | request.method = "GET"; |
| 9218 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 9219 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9220 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9221 | request.traffic_annotation = |
| 9222 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9223 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9224 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9225 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9226 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9227 | MockWrite( |
| 9228 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 9229 | "Host: www.example.org\r\n" |
| 9230 | "Connection: keep-alive\r\n" |
| 9231 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9232 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 9233 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 9234 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9235 | }; |
| 9236 | |
| 9237 | // Sever accepts the authorization. |
| 9238 | MockRead data_reads1[] = { |
| 9239 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9240 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9241 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9242 | }; |
| 9243 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9244 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9245 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9246 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9247 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9248 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9249 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9250 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9251 | |
| 9252 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9253 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9254 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9255 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9256 | ASSERT_TRUE(response); |
| 9257 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9258 | } |
| 9259 | } |
| 9260 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9261 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9262 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9263 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9264 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9265 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9266 | |
| 9267 | // Setup some state (which we expect ResetStateForRestart() will clear). |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 9268 | trans.read_buf_ = base::MakeRefCounted<IOBuffer>(15); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9269 | trans.read_buf_len_ = 15; |
| 9270 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9271 | |
| 9272 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9273 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9274 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9275 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9276 | response->response_time = base::Time::Now(); |
| 9277 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9278 | |
| 9279 | { // Setup state for response_.vary_data |
| 9280 | HttpRequestInfo request; |
| 9281 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 9282 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 9283 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9284 | request.extra_headers.SetHeader("Foo", "1"); |
| 9285 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9286 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9287 | } |
| 9288 | |
| 9289 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9290 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9291 | |
| 9292 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9293 | EXPECT_FALSE(trans.read_buf_); |
| 9294 | EXPECT_EQ(0, trans.read_buf_len_); |
| 9295 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9296 | EXPECT_FALSE(response->auth_challenge); |
| 9297 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 9298 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9299 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9300 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9301 | } |
| 9302 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9303 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9304 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9305 | HttpRequestInfo request; |
| 9306 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9307 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9308 | request.traffic_annotation = |
| 9309 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9310 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9311 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9312 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9313 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9314 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9315 | MockWrite( |
| 9316 | "GET / HTTP/1.1\r\n" |
| 9317 | "Host: www.example.org\r\n" |
| 9318 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9319 | }; |
| 9320 | |
| 9321 | MockRead data_reads[] = { |
| 9322 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9323 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9324 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9325 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9326 | }; |
| 9327 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 9328 | StaticSocketDataProvider ssl_bad_certificate; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9329 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9330 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9331 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9332 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9333 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9334 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9335 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9336 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9337 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9338 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9339 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9340 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9341 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9342 | |
| 9343 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9344 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9345 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9346 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9347 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9348 | |
| 9349 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9350 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9351 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9352 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9353 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9354 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9355 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9356 | } |
| 9357 | |
| 9358 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 9359 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9360 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9361 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9362 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9363 | |
| 9364 | HttpRequestInfo request; |
| 9365 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9366 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9367 | request.traffic_annotation = |
| 9368 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9369 | |
| 9370 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9371 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9372 | "Host: www.example.org:443\r\n" |
| 9373 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9374 | }; |
| 9375 | |
| 9376 | MockRead proxy_reads[] = { |
| 9377 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9378 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9379 | }; |
| 9380 | |
| 9381 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9382 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9383 | "Host: www.example.org:443\r\n" |
| 9384 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9385 | MockWrite("GET / HTTP/1.1\r\n" |
| 9386 | "Host: www.example.org\r\n" |
| 9387 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9388 | }; |
| 9389 | |
| 9390 | MockRead data_reads[] = { |
| 9391 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9392 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9393 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9394 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9395 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9396 | }; |
| 9397 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9398 | StaticSocketDataProvider ssl_bad_certificate(proxy_reads, proxy_writes); |
| 9399 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9400 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9401 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9402 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9403 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9404 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9405 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9406 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9407 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9408 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9409 | |
| 9410 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9411 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9412 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9413 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9414 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9415 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9416 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9417 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9418 | |
| 9419 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9420 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9421 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9422 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9423 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9424 | |
| 9425 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9426 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9427 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9428 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9429 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9430 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9431 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9432 | } |
| 9433 | } |
| 9434 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9435 | |
| 9436 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9437 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9438 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9439 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9440 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9441 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9442 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9443 | |
| 9444 | HttpRequestInfo request; |
| 9445 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9446 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9447 | request.traffic_annotation = |
| 9448 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9449 | |
| 9450 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9451 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9452 | "Host: www.example.org:443\r\n" |
| 9453 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9454 | MockWrite("GET / HTTP/1.1\r\n" |
| 9455 | "Host: www.example.org\r\n" |
| 9456 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9457 | }; |
| 9458 | |
| 9459 | MockRead data_reads[] = { |
| 9460 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9461 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9462 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9463 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9464 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9465 | }; |
| 9466 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9467 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9468 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9469 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9470 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9471 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9472 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9473 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9474 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9475 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9476 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9477 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9478 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9479 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9480 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9481 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9482 | |
| 9483 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9484 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9485 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9486 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9487 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9488 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9489 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9490 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9491 | EXPECT_EQ(200, response->headers->response_code()); |
| 9492 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9493 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9494 | |
| 9495 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9496 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9497 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9498 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9499 | } |
| 9500 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9501 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9502 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9503 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9504 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9505 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9506 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9507 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9508 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9509 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 9510 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 9511 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 9512 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9513 | HttpRequestInfo request; |
| 9514 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9515 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9516 | request.traffic_annotation = |
| 9517 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9518 | |
| 9519 | MockWrite data_writes[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9520 | MockWrite(ASYNC, 0, |
| 9521 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9522 | "Host: www.example.org:443\r\n" |
| 9523 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9524 | }; |
| 9525 | |
| 9526 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9527 | // Pause on first read. |
| 9528 | MockRead(ASYNC, ERR_IO_PENDING, 1), |
| 9529 | MockRead(ASYNC, 2, "HTTP/1.1 302 Redirect\r\n"), |
| 9530 | MockRead(ASYNC, 3, "Location: http://login.example.com/\r\n"), |
| 9531 | MockRead(ASYNC, 4, "Content-Length: 0\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9532 | }; |
| 9533 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9534 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9535 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9536 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9537 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9538 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9539 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9540 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9541 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9542 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9543 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9544 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9545 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9546 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9547 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
| 9548 | |
| 9549 | // Host resolution takes |kTimeIncrement|. |
| 9550 | FastForwardBy(kTimeIncrement); |
| 9551 | // Resolving the current request with |ResolveNow| will cause the pending |
| 9552 | // request to instantly complete, and the async connect will start as well. |
| 9553 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 9554 | |
| 9555 | // Connecting takes |kTimeIncrement|. |
| 9556 | FastForwardBy(kTimeIncrement); |
| 9557 | data.RunUntilPaused(); |
| 9558 | |
| 9559 | // The server takes |kTimeIncrement| to respond. |
| 9560 | FastForwardBy(kTimeIncrement); |
| 9561 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9562 | |
| 9563 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9564 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9565 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9566 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9567 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9568 | |
| 9569 | EXPECT_EQ(302, response->headers->response_code()); |
| 9570 | std::string url; |
| 9571 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 9572 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9573 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9574 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9575 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9576 | |
| 9577 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 9578 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9579 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9580 | // In the case of redirects from proxies, just as with all responses from |
| 9581 | // proxies, DNS and SSL times reflect timing to look up the destination's |
| 9582 | // name, and negotiate an SSL connection to it (Neither of which are done in |
| 9583 | // this case), which the DNS and SSL times for the proxy are all included in |
| 9584 | // connect_start / connect_end. See |
| 9585 | // HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 9586 | |
| 9587 | EXPECT_TRUE(load_timing_info.connect_timing.dns_start.is_null()); |
| 9588 | EXPECT_TRUE(load_timing_info.connect_timing.dns_end.is_null()); |
| 9589 | EXPECT_TRUE(load_timing_info.connect_timing.ssl_start.is_null()); |
| 9590 | EXPECT_TRUE(load_timing_info.connect_timing.ssl_end.is_null()); |
| 9591 | |
| 9592 | EXPECT_EQ(start_time, load_timing_info.proxy_resolve_start); |
| 9593 | EXPECT_EQ(start_time, load_timing_info.proxy_resolve_end); |
| 9594 | EXPECT_EQ(start_time, load_timing_info.connect_timing.connect_start); |
| 9595 | EXPECT_EQ(start_time + 3 * kTimeIncrement, |
| 9596 | load_timing_info.connect_timing.connect_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9597 | |
| 9598 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 9599 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 9600 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9601 | } |
| 9602 | |
| 9603 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9604 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9605 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9606 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9607 | TestNetLog net_log; |
| 9608 | session_deps_.net_log = &net_log; |
| 9609 | |
| 9610 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 9611 | const base::TimeDelta kTimeIncrement = base::TimeDelta::FromSeconds(4); |
| 9612 | session_deps_.host_resolver->set_ondemand_mode(true); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9613 | |
| 9614 | HttpRequestInfo request; |
| 9615 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9616 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9617 | request.traffic_annotation = |
| 9618 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9619 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9620 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9621 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9622 | spdy::SpdySerializedFrame goaway( |
| 9623 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9624 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9625 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9626 | CreateMockWrite(goaway, 3, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9627 | }; |
| 9628 | |
| 9629 | static const char* const kExtraHeaders[] = { |
| 9630 | "location", |
| 9631 | "http://login.example.com/", |
| 9632 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9633 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9634 | "302", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9635 | MockRead data_reads[] = { |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9636 | // Pause on first read. |
| 9637 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp, 2), |
| 9638 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9639 | }; |
| 9640 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9641 | SequencedSocketData data(MockConnect(ASYNC, OK), data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9642 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9643 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9644 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9645 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9646 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9647 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9648 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9649 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9650 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9651 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9652 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9653 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9654 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9655 | EXPECT_TRUE(session_deps_.host_resolver->has_pending_requests()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9656 | |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9657 | // Host resolution takes |kTimeIncrement|. |
| 9658 | FastForwardBy(kTimeIncrement); |
| 9659 | // Resolving the current request with |ResolveNow| will cause the pending |
| 9660 | // request to instantly complete, and the async connect will start as well. |
| 9661 | session_deps_.host_resolver->ResolveOnlyRequestNow(); |
| 9662 | |
| 9663 | // Connecting takes |kTimeIncrement|. |
| 9664 | FastForwardBy(kTimeIncrement); |
| 9665 | data.RunUntilPaused(); |
| 9666 | |
| 9667 | FastForwardBy(kTimeIncrement); |
| 9668 | data.Resume(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9669 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9670 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9671 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9672 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9673 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9674 | |
| 9675 | EXPECT_EQ(302, response->headers->response_code()); |
| 9676 | std::string url; |
| 9677 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 9678 | EXPECT_EQ("http://login.example.com/", url); |
Matt Menke | ecfecfc7 | 2019-02-05 19:15:28 | [diff] [blame] | 9679 | |
| 9680 | LoadTimingInfo load_timing_info; |
| 9681 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 9682 | |
| 9683 | EXPECT_FALSE(load_timing_info.socket_reused); |
| 9684 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
| 9685 | |
| 9686 | // No proxy resolution times, since there's no PAC script. |
| 9687 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 9688 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 9689 | |
| 9690 | // In the case of redirects from proxies, just as with all responses from |
| 9691 | // proxies, DNS and SSL times reflect timing to look up the destination's |
| 9692 | // name, and negotiate an SSL connection to it (Neither of which are done in |
| 9693 | // this case), which the DNS and SSL times for the proxy are all included in |
| 9694 | // connect_start / connect_end. See |
| 9695 | // HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 9696 | |
| 9697 | EXPECT_TRUE(load_timing_info.connect_timing.dns_start.is_null()); |
| 9698 | EXPECT_TRUE(load_timing_info.connect_timing.dns_end.is_null()); |
| 9699 | EXPECT_TRUE(load_timing_info.connect_timing.ssl_start.is_null()); |
| 9700 | EXPECT_TRUE(load_timing_info.connect_timing.ssl_end.is_null()); |
| 9701 | |
| 9702 | EXPECT_EQ(start_time, load_timing_info.connect_timing.connect_start); |
| 9703 | EXPECT_EQ(start_time + 3 * kTimeIncrement, |
| 9704 | load_timing_info.connect_timing.connect_end); |
| 9705 | |
| 9706 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 9707 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 9708 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9709 | } |
| 9710 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9711 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9712 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9713 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9714 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9715 | |
| 9716 | HttpRequestInfo request; |
| 9717 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9718 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9719 | request.traffic_annotation = |
| 9720 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9721 | |
| 9722 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9723 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9724 | "Host: www.example.org:443\r\n" |
| 9725 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9726 | }; |
| 9727 | |
| 9728 | MockRead data_reads[] = { |
| 9729 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 9730 | MockRead("Content-Length: 23\r\n\r\n"), |
| 9731 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9732 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9733 | }; |
| 9734 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9735 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9736 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9737 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9738 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9739 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9740 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9741 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9742 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9743 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9744 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9745 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9746 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9747 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9748 | |
| 9749 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9750 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9751 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9752 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9753 | } |
| 9754 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9755 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9756 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9757 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9758 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9759 | |
| 9760 | HttpRequestInfo request; |
| 9761 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9762 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9763 | request.traffic_annotation = |
| 9764 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9765 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9766 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9767 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9768 | spdy::SpdySerializedFrame rst( |
| 9769 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9770 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9771 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9772 | }; |
| 9773 | |
| 9774 | static const char* const kExtraHeaders[] = { |
| 9775 | "location", |
| 9776 | "http://login.example.com/", |
| 9777 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9778 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9779 | "404", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9780 | spdy::SpdySerializedFrame body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9781 | spdy_util_.ConstructSpdyDataFrame(1, "The host does not exist", true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9782 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9783 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9784 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9785 | }; |
| 9786 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9787 | SequencedSocketData data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9788 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9789 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9790 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9791 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9792 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9793 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9794 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9795 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9796 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9797 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9798 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9799 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9800 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9801 | |
| 9802 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9803 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9804 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9805 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9806 | } |
| 9807 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9808 | // Test the request-challenge-retry sequence for basic auth, through |
| 9809 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9810 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9811 | HttpRequestInfo request; |
| 9812 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9813 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9814 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 9815 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9816 | request.traffic_annotation = |
| 9817 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9818 | |
| 9819 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9820 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9821 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9822 | "HTTPS myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9823 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9824 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9825 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9826 | |
| 9827 | // Since we have proxy, should try to establish tunnel. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9828 | spdy::SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9829 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9830 | spdy::SpdySerializedFrame rst( |
| 9831 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9832 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9833 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9834 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9835 | // be issuing -- the final header line contains the credentials. |
| 9836 | const char* const kAuthCredentials[] = { |
| 9837 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 9838 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9839 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9840 | kAuthCredentials, base::size(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9841 | HostPortPair("www.example.org", 443))); |
| 9842 | // fetch https://www.example.org/ via HTTP |
| 9843 | const char get[] = |
| 9844 | "GET / HTTP/1.1\r\n" |
| 9845 | "Host: www.example.org\r\n" |
| 9846 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9847 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9848 | spdy_util_.ConstructSpdyDataFrame(3, get, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9849 | |
| 9850 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9851 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 9852 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9853 | }; |
| 9854 | |
| 9855 | // The proxy responds to the connect with a 407, using a persistent |
| 9856 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 9857 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9858 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9859 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 9860 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9861 | spdy::SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9862 | kAuthStatus, kAuthChallenge, base::size(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9863 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9864 | spdy::SpdySerializedFrame conn_resp( |
| 9865 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9866 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 9867 | "Content-Length: 5\r\n\r\n"; |
| 9868 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9869 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9870 | spdy_util_.ConstructSpdyDataFrame(3, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9871 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9872 | spdy_util_.ConstructSpdyDataFrame(3, "hello", false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9873 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9874 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 9875 | CreateMockRead(conn_resp, 4, ASYNC), |
| 9876 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 9877 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9878 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9879 | }; |
| 9880 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9881 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9882 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9883 | // Negotiate SPDY to the proxy |
| 9884 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9885 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9886 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9887 | // Vanilla SSL to the server |
| 9888 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9889 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9890 | |
| 9891 | TestCompletionCallback callback1; |
| 9892 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9893 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9894 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9895 | |
| 9896 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9897 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9898 | |
| 9899 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9900 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 9901 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9902 | log.GetEntries(&entries); |
| 9903 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 9904 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 9905 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9906 | ExpectLogContainsSomewhere( |
| 9907 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 9908 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 9909 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9910 | |
| 9911 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9912 | ASSERT_TRUE(response); |
| 9913 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9914 | EXPECT_EQ(407, response->headers->response_code()); |
| 9915 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9916 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 9917 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9918 | |
| 9919 | TestCompletionCallback callback2; |
| 9920 | |
| 9921 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9922 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9923 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9924 | |
| 9925 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9926 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9927 | |
| 9928 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9929 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9930 | |
| 9931 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9932 | EXPECT_EQ(200, response->headers->response_code()); |
| 9933 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 9934 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9935 | |
| 9936 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9937 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9938 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9939 | LoadTimingInfo load_timing_info; |
| 9940 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9941 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9942 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9943 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9944 | trans.reset(); |
| 9945 | session->CloseAllConnections(); |
| 9946 | } |
| 9947 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9948 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 9949 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9950 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9951 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9952 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9953 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 9954 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9955 | HttpRequestInfo request; |
| 9956 | HttpRequestInfo push_request; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9957 | request.traffic_annotation = |
| 9958 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9959 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9960 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9961 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9962 | push_request.method = "GET"; |
| 9963 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9964 | push_request.traffic_annotation = |
| 9965 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9966 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9967 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9968 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9969 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9970 | "HTTPS myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9971 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9972 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9973 | |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 9974 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 9975 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9976 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9977 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9978 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9979 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9980 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9981 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9982 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9983 | |
| 9984 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9985 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9986 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9987 | }; |
| 9988 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9989 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 9990 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
| 9991 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9992 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9993 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9994 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9995 | spdy::SpdySerializedFrame stream1_body( |
| 9996 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9997 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9998 | spdy::SpdySerializedFrame stream2_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9999 | spdy_util_.ConstructSpdyDataFrame(2, "pushed", true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10000 | |
| 10001 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 10002 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 10003 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10004 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10005 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10006 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10007 | }; |
| 10008 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10009 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10010 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10011 | // Negotiate SPDY to the proxy |
| 10012 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10013 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10014 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10015 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10016 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10017 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10018 | TestCompletionCallback callback; |
| 10019 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10020 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10021 | |
| 10022 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10023 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10024 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10025 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10026 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10027 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 10028 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10029 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10030 | |
| 10031 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10032 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10033 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 10034 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10035 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10036 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10037 | |
| 10038 | EXPECT_EQ(200, response->headers->response_code()); |
| 10039 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10040 | |
| 10041 | std::string response_data; |
| 10042 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10043 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10044 | EXPECT_EQ("hello!", response_data); |
| 10045 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10046 | LoadTimingInfo load_timing_info; |
| 10047 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 10048 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10049 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10050 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10051 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10052 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10053 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 10054 | |
| 10055 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10056 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10057 | EXPECT_EQ("pushed", response_data); |
| 10058 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10059 | LoadTimingInfo push_load_timing_info; |
| 10060 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 10061 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 10062 | // The transactions should share a socket ID, despite being for different |
| 10063 | // origins. |
| 10064 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 10065 | push_load_timing_info.socket_log_id); |
| 10066 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10067 | trans.reset(); |
| 10068 | push_trans.reset(); |
| 10069 | session->CloseAllConnections(); |
| 10070 | } |
| 10071 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10072 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10073 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10074 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10075 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10076 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 10077 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10078 | HttpRequestInfo request; |
| 10079 | |
| 10080 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10081 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10082 | request.traffic_annotation = |
| 10083 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10084 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10085 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10086 | "https://myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10087 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10088 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10089 | |
| 10090 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10091 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10092 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10093 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10094 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10095 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10096 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10097 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10098 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10099 | spdy::SpdySerializedFrame push_rst( |
| 10100 | spdy_util_.ConstructSpdyRstStream(2, spdy::ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10101 | |
| 10102 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10103 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10104 | }; |
| 10105 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10106 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10107 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10108 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10109 | spdy::SpdySerializedFrame stream1_body( |
| 10110 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10111 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10112 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 10113 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10114 | |
| 10115 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10116 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10117 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 10118 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 10119 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10120 | }; |
| 10121 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10122 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10123 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10124 | // Negotiate SPDY to the proxy |
| 10125 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10126 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10127 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10128 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10129 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10130 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10131 | TestCompletionCallback callback; |
| 10132 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10133 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10134 | |
| 10135 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10136 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10137 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10138 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10139 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10140 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10141 | |
| 10142 | EXPECT_EQ(200, response->headers->response_code()); |
| 10143 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10144 | |
| 10145 | std::string response_data; |
| 10146 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10147 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10148 | EXPECT_EQ("hello!", response_data); |
| 10149 | |
| 10150 | trans.reset(); |
| 10151 | session->CloseAllConnections(); |
| 10152 | } |
| 10153 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10154 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 10155 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10156 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10157 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10158 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10159 | proxy_delegate->set_trusted_spdy_proxy( |
| 10160 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 10161 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10162 | HttpRequestInfo request; |
| 10163 | |
| 10164 | request.method = "GET"; |
| 10165 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10166 | request.traffic_annotation = |
| 10167 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10168 | |
| 10169 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10170 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10171 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10172 | BoundTestNetLog log; |
| 10173 | session_deps_.net_log = log.bound().net_log(); |
| 10174 | |
| 10175 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10176 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10177 | proxy_delegate.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10178 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10179 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10180 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10181 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10182 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10183 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10184 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10185 | |
| 10186 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10187 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10188 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10189 | }; |
| 10190 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10191 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10192 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10193 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10194 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 10195 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 10196 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10197 | spdy::SpdySerializedFrame stream1_body( |
| 10198 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10199 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10200 | spdy::SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10201 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10202 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10203 | spdy::SpdySerializedFrame stream2_body( |
| 10204 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10205 | |
| 10206 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10207 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10208 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10209 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10210 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10211 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10212 | }; |
| 10213 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10214 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10215 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 10216 | // Negotiate SPDY to the proxy |
| 10217 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10218 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10219 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 10220 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10221 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10222 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10223 | TestCompletionCallback callback; |
| 10224 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10225 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10226 | |
| 10227 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10228 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10229 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10230 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10231 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10232 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10233 | |
| 10234 | EXPECT_EQ(200, response->headers->response_code()); |
| 10235 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10236 | |
| 10237 | std::string response_data; |
| 10238 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10239 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10240 | EXPECT_EQ("hello!", response_data); |
| 10241 | |
| 10242 | trans.reset(); |
| 10243 | session->CloseAllConnections(); |
| 10244 | } |
| 10245 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10246 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 10247 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10248 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10249 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10250 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10251 | |
| 10252 | HttpRequestInfo request; |
| 10253 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10254 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10255 | request.traffic_annotation = |
| 10256 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10257 | |
| 10258 | // Attempt to fetch the URL from a server with a bad cert |
| 10259 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10260 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10261 | "Host: www.example.org:443\r\n" |
| 10262 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10263 | }; |
| 10264 | |
| 10265 | MockRead bad_cert_reads[] = { |
| 10266 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10267 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10268 | }; |
| 10269 | |
| 10270 | // Attempt to fetch the URL with a good cert |
| 10271 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10272 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10273 | "Host: www.example.org:443\r\n" |
| 10274 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10275 | MockWrite("GET / HTTP/1.1\r\n" |
| 10276 | "Host: www.example.org\r\n" |
| 10277 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10278 | }; |
| 10279 | |
| 10280 | MockRead good_cert_reads[] = { |
| 10281 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 10282 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10283 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10284 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10285 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10286 | }; |
| 10287 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10288 | StaticSocketDataProvider ssl_bad_certificate(bad_cert_reads, bad_cert_writes); |
| 10289 | StaticSocketDataProvider data(good_cert_reads, good_data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10290 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 10291 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10292 | |
| 10293 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10294 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10295 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 10296 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10297 | |
| 10298 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10299 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10300 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10301 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10302 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10303 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10304 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10305 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10306 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10307 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10308 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10309 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10310 | |
| 10311 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10312 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10313 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10314 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10315 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10316 | |
| 10317 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10318 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10319 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10320 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10321 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10322 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10323 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10324 | } |
| 10325 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10326 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10327 | HttpRequestInfo request; |
| 10328 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10329 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10330 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10331 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10332 | request.traffic_annotation = |
| 10333 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10334 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10335 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10336 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10337 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10338 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10339 | MockWrite( |
| 10340 | "GET / HTTP/1.1\r\n" |
| 10341 | "Host: www.example.org\r\n" |
| 10342 | "Connection: keep-alive\r\n" |
| 10343 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10344 | }; |
| 10345 | |
| 10346 | // Lastly, the server responds with the actual content. |
| 10347 | MockRead data_reads[] = { |
| 10348 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10349 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10350 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10351 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10352 | }; |
| 10353 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10354 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10355 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10356 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10357 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10358 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10359 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10360 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10361 | |
| 10362 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10363 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10364 | } |
| 10365 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10366 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10367 | HttpRequestInfo request; |
| 10368 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10369 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10370 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10371 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10372 | request.traffic_annotation = |
| 10373 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10374 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10375 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10376 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10377 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10378 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10379 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10380 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10381 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10382 | "Host: www.example.org:443\r\n" |
| 10383 | "Proxy-Connection: keep-alive\r\n" |
| 10384 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10385 | }; |
| 10386 | MockRead data_reads[] = { |
| 10387 | // Return an error, so the transaction stops here (this test isn't |
| 10388 | // interested in the rest). |
| 10389 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 10390 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10391 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 10392 | }; |
| 10393 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10394 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10395 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10396 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10397 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10398 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10399 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10400 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10401 | |
| 10402 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10403 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10404 | } |
| 10405 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10406 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10407 | HttpRequestInfo request; |
| 10408 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10409 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 10410 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 10411 | "http://the.previous.site.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10412 | request.traffic_annotation = |
| 10413 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10414 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10415 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10416 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10417 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10418 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10419 | MockWrite( |
| 10420 | "GET / HTTP/1.1\r\n" |
| 10421 | "Host: www.example.org\r\n" |
| 10422 | "Connection: keep-alive\r\n" |
| 10423 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10424 | }; |
| 10425 | |
| 10426 | // Lastly, the server responds with the actual content. |
| 10427 | MockRead data_reads[] = { |
| 10428 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10429 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10430 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10431 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10432 | }; |
| 10433 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10434 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10435 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10436 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10437 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10438 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10439 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10440 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10441 | |
| 10442 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10443 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10444 | } |
| 10445 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10446 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10447 | HttpRequestInfo request; |
| 10448 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10449 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10450 | request.traffic_annotation = |
| 10451 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10452 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10453 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10454 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10455 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10456 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10457 | MockWrite( |
| 10458 | "POST / HTTP/1.1\r\n" |
| 10459 | "Host: www.example.org\r\n" |
| 10460 | "Connection: keep-alive\r\n" |
| 10461 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10462 | }; |
| 10463 | |
| 10464 | // Lastly, the server responds with the actual content. |
| 10465 | MockRead data_reads[] = { |
| 10466 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10467 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10468 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10469 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10470 | }; |
| 10471 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10472 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10473 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10474 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10475 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10476 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10477 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10478 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10479 | |
| 10480 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10481 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10482 | } |
| 10483 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10484 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10485 | HttpRequestInfo request; |
| 10486 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10487 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10488 | request.traffic_annotation = |
| 10489 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10490 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10491 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10492 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10493 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10494 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10495 | MockWrite( |
| 10496 | "PUT / HTTP/1.1\r\n" |
| 10497 | "Host: www.example.org\r\n" |
| 10498 | "Connection: keep-alive\r\n" |
| 10499 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10500 | }; |
| 10501 | |
| 10502 | // Lastly, the server responds with the actual content. |
| 10503 | MockRead data_reads[] = { |
| 10504 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10505 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10506 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10507 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10508 | }; |
| 10509 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10510 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10511 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10512 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10513 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10514 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10515 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10516 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10517 | |
| 10518 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10519 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10520 | } |
| 10521 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10522 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10523 | HttpRequestInfo request; |
| 10524 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10525 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10526 | request.traffic_annotation = |
| 10527 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10528 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10529 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10530 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10531 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10532 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 10533 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 10534 | "Host: www.example.org\r\n" |
| 10535 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10536 | }; |
| 10537 | |
| 10538 | // Lastly, the server responds with the actual content. |
| 10539 | MockRead data_reads[] = { |
| 10540 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10541 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10542 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10543 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10544 | }; |
| 10545 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10546 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10547 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10548 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10549 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10550 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10551 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10552 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10553 | |
| 10554 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10555 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10556 | } |
| 10557 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10558 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[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] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10562 | request.load_flags = LOAD_BYPASS_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10563 | request.traffic_annotation = |
| 10564 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10565 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10566 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10567 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10568 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10569 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10570 | MockWrite( |
| 10571 | "GET / HTTP/1.1\r\n" |
| 10572 | "Host: www.example.org\r\n" |
| 10573 | "Connection: keep-alive\r\n" |
| 10574 | "Pragma: no-cache\r\n" |
| 10575 | "Cache-Control: no-cache\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_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10599 | HttpRequestInfo request; |
| 10600 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10601 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10602 | request.load_flags = LOAD_VALIDATE_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10603 | request.traffic_annotation = |
| 10604 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10605 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10606 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10607 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10608 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10609 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10610 | MockWrite( |
| 10611 | "GET / HTTP/1.1\r\n" |
| 10612 | "Host: www.example.org\r\n" |
| 10613 | "Connection: keep-alive\r\n" |
| 10614 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10615 | }; |
| 10616 | |
| 10617 | // Lastly, the server responds with the actual content. |
| 10618 | MockRead data_reads[] = { |
| 10619 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10620 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10621 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10622 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10623 | }; |
| 10624 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10625 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10626 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10627 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10628 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10629 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10630 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10631 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10632 | |
| 10633 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10634 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10635 | } |
| 10636 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10637 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10638 | HttpRequestInfo request; |
| 10639 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10640 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10641 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10642 | request.traffic_annotation = |
| 10643 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10644 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10645 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10646 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10647 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10648 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10649 | MockWrite( |
| 10650 | "GET / HTTP/1.1\r\n" |
| 10651 | "Host: www.example.org\r\n" |
| 10652 | "Connection: keep-alive\r\n" |
| 10653 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10654 | }; |
| 10655 | |
| 10656 | // Lastly, the server responds with the actual content. |
| 10657 | MockRead data_reads[] = { |
| 10658 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10659 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10660 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10661 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10662 | }; |
| 10663 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10664 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10665 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10666 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10667 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10668 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10669 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10670 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10671 | |
| 10672 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10673 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10674 | } |
| 10675 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10676 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10677 | HttpRequestInfo request; |
| 10678 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10679 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10680 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 10681 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 10682 | request.extra_headers.SetHeader("FoO", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10683 | request.traffic_annotation = |
| 10684 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10685 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10686 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10687 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10688 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10689 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10690 | MockWrite( |
| 10691 | "GET / HTTP/1.1\r\n" |
| 10692 | "Host: www.example.org\r\n" |
| 10693 | "Connection: keep-alive\r\n" |
| 10694 | "referer: www.foo.com\r\n" |
| 10695 | "hEllo: Kitty\r\n" |
| 10696 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10697 | }; |
| 10698 | |
| 10699 | // Lastly, the server responds with the actual content. |
| 10700 | MockRead data_reads[] = { |
| 10701 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10702 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10703 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10704 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10705 | }; |
| 10706 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10707 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10708 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10709 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10710 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10711 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10712 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10713 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10714 | |
| 10715 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10716 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10717 | } |
| 10718 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10719 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10720 | HttpRequestInfo request; |
| 10721 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10722 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10723 | request.traffic_annotation = |
| 10724 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10725 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10726 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10727 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10728 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10729 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10730 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10731 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10732 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10733 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10734 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10735 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 10736 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10737 | |
| 10738 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10739 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 10740 | MockWrite("GET / HTTP/1.1\r\n" |
| 10741 | "Host: www.example.org\r\n" |
| 10742 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10743 | |
| 10744 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10745 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 10746 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10747 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10748 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10749 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10750 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10751 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10752 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10753 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10754 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10755 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10756 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10757 | |
| 10758 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10759 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10760 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10761 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10762 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10763 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10764 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10765 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10766 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10767 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10768 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10769 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10770 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10771 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10772 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10773 | EXPECT_EQ("Payload", response_text); |
| 10774 | } |
| 10775 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10776 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10777 | HttpRequestInfo request; |
| 10778 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10779 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10780 | request.traffic_annotation = |
| 10781 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10782 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10783 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10784 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10785 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10786 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10787 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10788 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10789 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10790 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10791 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10792 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 10793 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10794 | |
| 10795 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10796 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10797 | base::size(write_buffer)), |
| 10798 | MockWrite("GET / HTTP/1.1\r\n" |
| 10799 | "Host: www.example.org\r\n" |
| 10800 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10801 | |
| 10802 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10803 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 10804 | base::size(read_buffer)), |
| 10805 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10806 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10807 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10808 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10809 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10810 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10811 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10812 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10813 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10814 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10815 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10816 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10817 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10818 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10819 | |
| 10820 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10821 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10822 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10823 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10824 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10825 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10826 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10827 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10828 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10829 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10830 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10831 | |
| 10832 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10833 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10834 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10835 | EXPECT_EQ("Payload", response_text); |
| 10836 | } |
| 10837 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10838 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10839 | HttpRequestInfo request; |
| 10840 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10841 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10842 | request.traffic_annotation = |
| 10843 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10844 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10845 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10846 | "socks4://myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10847 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10848 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10849 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10850 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10851 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10852 | |
| 10853 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 10854 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10855 | |
| 10856 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10857 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 10858 | MockWrite("GET / HTTP/1.1\r\n" |
| 10859 | "Host: www.example.org\r\n" |
| 10860 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10861 | |
| 10862 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10863 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 10864 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10865 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10866 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10867 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10868 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10869 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10870 | |
| 10871 | TestCompletionCallback callback; |
| 10872 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10873 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10874 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10875 | |
| 10876 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10877 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10878 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10879 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10880 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10881 | |
| 10882 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10883 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10884 | TestLoadTimingNotReused(load_timing_info, |
| 10885 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10886 | |
| 10887 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10888 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10889 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10890 | EXPECT_EQ("Payload", response_text); |
| 10891 | } |
| 10892 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10893 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10894 | HttpRequestInfo request; |
| 10895 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10896 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10897 | request.traffic_annotation = |
| 10898 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10899 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10900 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10901 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10902 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10903 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10904 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10905 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10906 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10907 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10908 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10909 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 10910 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10911 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10912 | 0x05, // Version |
| 10913 | 0x01, // Command (CONNECT) |
| 10914 | 0x00, // Reserved. |
| 10915 | 0x03, // Address type (DOMAINNAME). |
| 10916 | 0x0F, // Length of domain (15) |
| 10917 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 10918 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10919 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10920 | const char kSOCKS5OkResponse[] = |
| 10921 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 10922 | |
| 10923 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10924 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
| 10925 | MockWrite(ASYNC, kSOCKS5OkRequest, base::size(kSOCKS5OkRequest)), |
| 10926 | MockWrite("GET / HTTP/1.1\r\n" |
| 10927 | "Host: www.example.org\r\n" |
| 10928 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10929 | |
| 10930 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10931 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 10932 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 10933 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10934 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10935 | MockRead("Payload"), |
| 10936 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10937 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10938 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10939 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10940 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10941 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10942 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10943 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10944 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10945 | |
| 10946 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10947 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10948 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10949 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10950 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10951 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10952 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10953 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10954 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10955 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10956 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10957 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10958 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10959 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10960 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10961 | EXPECT_EQ("Payload", response_text); |
| 10962 | } |
| 10963 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10964 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10965 | HttpRequestInfo request; |
| 10966 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10967 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10968 | request.traffic_annotation = |
| 10969 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10970 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10971 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10972 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10973 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10974 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10975 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10976 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10977 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10978 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10979 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10980 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 10981 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10982 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10983 | 0x05, // Version |
| 10984 | 0x01, // Command (CONNECT) |
| 10985 | 0x00, // Reserved. |
| 10986 | 0x03, // Address type (DOMAINNAME). |
| 10987 | 0x0F, // Length of domain (15) |
| 10988 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 10989 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10990 | }; |
| 10991 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10992 | const char kSOCKS5OkResponse[] = |
| 10993 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 10994 | |
| 10995 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10996 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10997 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10998 | base::size(kSOCKS5OkRequest)), |
| 10999 | MockWrite("GET / HTTP/1.1\r\n" |
| 11000 | "Host: www.example.org\r\n" |
| 11001 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 11002 | |
| 11003 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11004 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 11005 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 11006 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 11007 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 11008 | MockRead("Payload"), |
| 11009 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11010 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11011 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11012 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11013 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11014 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11015 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11016 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11017 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11018 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11019 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11020 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11021 | |
| 11022 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11023 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11024 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11025 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11026 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 11027 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11028 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11029 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11030 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 11031 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 11032 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 11033 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11034 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11035 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11036 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 11037 | EXPECT_EQ("Payload", response_text); |
| 11038 | } |
| 11039 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11040 | namespace { |
| 11041 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11042 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11043 | |
| 11044 | struct GroupNameTest { |
| 11045 | std::string proxy_server; |
| 11046 | std::string url; |
| 11047 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11048 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11049 | }; |
| 11050 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11051 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11052 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11053 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11054 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11055 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11056 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11057 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11058 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11059 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 11060 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11061 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11062 | |
| 11063 | return session; |
| 11064 | } |
| 11065 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11066 | int GroupNameTransactionHelper(const std::string& url, |
| 11067 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11068 | HttpRequestInfo request; |
| 11069 | request.method = "GET"; |
| 11070 | request.url = GURL(url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11071 | request.traffic_annotation = |
| 11072 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11073 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11074 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11075 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11076 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11077 | |
| 11078 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11079 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11080 | } |
| 11081 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11082 | } // namespace |
| 11083 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11084 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11085 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11086 | { |
| 11087 | "", // unused |
| 11088 | "http://www.example.org/direct", |
| 11089 | "www.example.org:80", |
| 11090 | false, |
| 11091 | }, |
| 11092 | { |
| 11093 | "", // unused |
| 11094 | "http://[2001:1418:13:1::25]/direct", |
| 11095 | "[2001:1418:13:1::25]:80", |
| 11096 | false, |
| 11097 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11098 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11099 | // SSL Tests |
| 11100 | { |
| 11101 | "", // unused |
| 11102 | "https://www.example.org/direct_ssl", |
| 11103 | "ssl/www.example.org:443", |
| 11104 | true, |
| 11105 | }, |
| 11106 | { |
| 11107 | "", // unused |
| 11108 | "https://[2001:1418:13:1::25]/direct", |
| 11109 | "ssl/[2001:1418:13:1::25]:443", |
| 11110 | true, |
| 11111 | }, |
| 11112 | { |
| 11113 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 11114 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11115 | "ssl/host.with.alternate:443", |
| 11116 | true, |
| 11117 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11118 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11119 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11120 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11121 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11122 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11123 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11124 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 11125 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11126 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11127 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11128 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11129 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11130 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 11131 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11132 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11133 | |
| 11134 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11135 | GroupNameTransactionHelper(tests[i].url, session.get())); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 11136 | EXPECT_EQ(tests[i].expected_group_name, |
| 11137 | transport_conn_pool->last_group_name_received()); |
| 11138 | EXPECT_TRUE(transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11139 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11140 | } |
| 11141 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11142 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11143 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11144 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 11145 | "http_proxy", "http://www.example.org/http_proxy_normal", |
| 11146 | "http_proxy/www.example.org:80", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11147 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11148 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11149 | // SSL Tests |
| 11150 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 11151 | "http_proxy", "https://www.example.org/http_connect_ssl", |
| 11152 | "http_proxy/ssl/www.example.org:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11153 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11154 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11155 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 11156 | "http_proxy", "https://host.with.alternate/direct", |
| 11157 | "http_proxy/ssl/host.with.alternate:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11158 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 11159 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11160 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 11161 | "http_proxy", "ftp://ftp.google.com/http_proxy_normal", |
| 11162 | "http_proxy/ftp/ftp.google.com:21", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11163 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11164 | }; |
| 11165 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11166 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11167 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11168 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11169 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11170 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 11171 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11172 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11173 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11174 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11175 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11176 | HostPortPair("http_proxy", 80)); |
Matt Menke | 0754b5d0 | 2019-02-10 21:46:43 | [diff] [blame] | 11177 | CaptureGroupNameTransportSocketPool* http_proxy_pool = |
| 11178 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
Matt Menke | df126e0e | 2019-02-01 22:23:47 | [diff] [blame] | 11179 | CaptureGroupNameTransportSocketPool* ssl_conn_pool = |
| 11180 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11181 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 11182 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11183 | proxy_server, base::WrapUnique(http_proxy_pool)); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 11184 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11185 | proxy_server, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11186 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11187 | |
| 11188 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11189 | GroupNameTransactionHelper(tests[i].url, session.get())); |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11190 | if (tests[i].ssl) { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11191 | EXPECT_EQ(tests[i].expected_group_name, |
| 11192 | ssl_conn_pool->last_group_name_received()); |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11193 | } else { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11194 | EXPECT_EQ(tests[i].expected_group_name, |
| 11195 | http_proxy_pool->last_group_name_received()); |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11196 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11197 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11198 | } |
| 11199 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11200 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11201 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11202 | { |
| 11203 | "socks4://socks_proxy:1080", |
| 11204 | "http://www.example.org/socks4_direct", |
| 11205 | "socks4/www.example.org:80", |
| 11206 | false, |
| 11207 | }, |
| 11208 | { |
| 11209 | "socks5://socks_proxy:1080", |
| 11210 | "http://www.example.org/socks5_direct", |
| 11211 | "socks5/www.example.org:80", |
| 11212 | false, |
| 11213 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11214 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11215 | // SSL Tests |
| 11216 | { |
| 11217 | "socks4://socks_proxy:1080", |
| 11218 | "https://www.example.org/socks4_ssl", |
| 11219 | "socks4/ssl/www.example.org:443", |
| 11220 | true, |
| 11221 | }, |
| 11222 | { |
| 11223 | "socks5://socks_proxy:1080", |
| 11224 | "https://www.example.org/socks5_ssl", |
| 11225 | "socks5/ssl/www.example.org:443", |
| 11226 | true, |
| 11227 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11228 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11229 | { |
| 11230 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 11231 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11232 | "socks4/ssl/host.with.alternate:443", |
| 11233 | true, |
| 11234 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11235 | }; |
| 11236 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11237 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11238 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11239 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11240 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11241 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 11242 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 11243 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11244 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11245 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11246 | ProxyServer proxy_server( |
| 11247 | ProxyServer::FromURI(tests[i].proxy_server, ProxyServer::SCHEME_HTTP)); |
| 11248 | ASSERT_TRUE(proxy_server.is_valid()); |
Matt Menke | 4b412da | 2019-01-25 19:31:12 | [diff] [blame] | 11249 | CaptureGroupNameTransportSocketPool* socks_conn_pool = |
| 11250 | new CaptureGroupNameTransportSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11251 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
Matt Menke | 4b412da | 2019-01-25 19:31:12 | [diff] [blame] | 11252 | mock_pool_manager->SetSocketPoolForProxy(proxy_server, |
| 11253 | base::WrapUnique(socks_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11254 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11255 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11256 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11257 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11258 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11259 | GroupNameTransactionHelper(tests[i].url, session.get())); |
Matt Menke | 628d624f | 2019-02-09 00:40:24 | [diff] [blame] | 11260 | EXPECT_EQ(tests[i].expected_group_name, |
| 11261 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11262 | } |
| 11263 | } |
| 11264 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11265 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11266 | HttpRequestInfo request; |
| 11267 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11268 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11269 | request.traffic_annotation = |
| 11270 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11271 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11272 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11273 | "myproxy:70;foobar:80", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11274 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 11275 | // This simulates failure resolving all hostnames; that means we will fail |
| 11276 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11277 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11278 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11279 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11280 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11281 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11282 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11283 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11284 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11285 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11286 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11287 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11288 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11289 | } |
| 11290 | |
Miriam Gershenson | 2a01b16 | 2018-03-22 22:54:47 | [diff] [blame] | 11291 | // LOAD_BYPASS_CACHE should trigger the host cache bypass. |
| 11292 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11293 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 11294 | HttpRequestInfo request_info; |
| 11295 | request_info.method = "GET"; |
Miriam Gershenson | 2a01b16 | 2018-03-22 22:54:47 | [diff] [blame] | 11296 | request_info.load_flags = LOAD_BYPASS_CACHE; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 11297 | request_info.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11298 | request_info.traffic_annotation = |
| 11299 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11300 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 11301 | // Select a host resolver that does caching. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11302 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11303 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11304 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11305 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11306 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11307 | // 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] | 11308 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 11309 | HostPortPair("www.example.org", 80), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11310 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11311 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11312 | // 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] | 11313 | // we can tell if the next lookup hit the cache, or the "network". |
| 11314 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11315 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11316 | |
| 11317 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 11318 | // 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] | 11319 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11320 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11321 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11322 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11323 | // Run the request. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 11324 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11325 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11326 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11327 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11328 | |
| 11329 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11330 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11331 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11332 | } |
| 11333 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11334 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11335 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11336 | HttpRequestInfo request; |
| 11337 | request.method = "GET"; |
| 11338 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11339 | request.traffic_annotation = |
| 11340 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11341 | |
| 11342 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11343 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11344 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11345 | StaticSocketDataProvider data(base::span<MockRead>(), write_failure); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11346 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11347 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11348 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11349 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11350 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11351 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11352 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11353 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11354 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11355 | |
| 11356 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11357 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11358 | |
| 11359 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11360 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11361 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11362 | } |
| 11363 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11364 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11365 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11366 | HttpRequestInfo request; |
| 11367 | request.method = "GET"; |
| 11368 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11369 | request.traffic_annotation = |
| 11370 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11371 | |
| 11372 | MockRead data_reads[] = { |
| 11373 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11374 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11375 | }; |
| 11376 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11377 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11378 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11379 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11380 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11381 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11382 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11383 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11384 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11385 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11386 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11387 | |
| 11388 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11389 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11390 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11391 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11392 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11393 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11394 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11395 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11396 | |
| 11397 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11398 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11399 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11400 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11401 | |
| 11402 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11403 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11404 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11405 | } |
| 11406 | |
| 11407 | // Make sure that a dropped connection while draining the body for auth |
| 11408 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11409 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11410 | HttpRequestInfo request; |
| 11411 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11412 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11413 | request.traffic_annotation = |
| 11414 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11415 | |
| 11416 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11417 | MockWrite( |
| 11418 | "GET / HTTP/1.1\r\n" |
| 11419 | "Host: www.example.org\r\n" |
| 11420 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11421 | }; |
| 11422 | |
| 11423 | MockRead data_reads1[] = { |
| 11424 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 11425 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 11426 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11427 | MockRead("Content-Length: 14\r\n\r\n"), |
| 11428 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11429 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11430 | }; |
| 11431 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11432 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11433 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11434 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11435 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11436 | // be issuing -- the final header line contains the credentials. |
| 11437 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11438 | MockWrite( |
| 11439 | "GET / HTTP/1.1\r\n" |
| 11440 | "Host: www.example.org\r\n" |
| 11441 | "Connection: keep-alive\r\n" |
| 11442 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11443 | }; |
| 11444 | |
| 11445 | // Lastly, the server responds with the actual content. |
| 11446 | MockRead data_reads2[] = { |
| 11447 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11448 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11449 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11450 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11451 | }; |
| 11452 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11453 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11454 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11455 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11456 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11457 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11458 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11459 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11460 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11461 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11462 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11463 | |
| 11464 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11465 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11466 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11467 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11468 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11469 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11470 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11471 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11472 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11473 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11474 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11475 | |
| 11476 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11477 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11478 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11479 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11480 | ASSERT_TRUE(response); |
| 11481 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11482 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11483 | } |
| 11484 | |
| 11485 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11486 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11487 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11488 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11489 | |
| 11490 | HttpRequestInfo request; |
| 11491 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11492 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11493 | request.traffic_annotation = |
| 11494 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11495 | |
| 11496 | MockRead proxy_reads[] = { |
| 11497 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11498 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11499 | }; |
| 11500 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11501 | StaticSocketDataProvider data(proxy_reads, base::span<MockWrite>()); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11502 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11503 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11504 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11505 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11506 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11507 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11508 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11509 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11510 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11511 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11512 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11513 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11514 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11515 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11516 | |
| 11517 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11518 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11519 | } |
| 11520 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11521 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11522 | HttpRequestInfo request; |
| 11523 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11524 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11525 | request.traffic_annotation = |
| 11526 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11527 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11528 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11529 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11530 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11531 | MockRead data_reads[] = { |
| 11532 | 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] | 11533 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11534 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11535 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11536 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11537 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11538 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11539 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11540 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11541 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11542 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11543 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11544 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11545 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11546 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11547 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11548 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11549 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11550 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11551 | |
| 11552 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11553 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11554 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11555 | } |
| 11556 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11557 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11558 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11559 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11560 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 11561 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 11562 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11563 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11564 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11565 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11566 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11567 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11568 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11569 | |
| 11570 | HttpRequestInfo request; |
| 11571 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11572 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11573 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11574 | request.traffic_annotation = |
| 11575 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11576 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11577 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11578 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11579 | |
| 11580 | MockRead data_reads[] = { |
| 11581 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 11582 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11583 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11584 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11585 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11586 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11587 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11588 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11589 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11590 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11591 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11592 | |
| 11593 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11594 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11595 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11596 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11597 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11598 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 11599 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11600 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11601 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11602 | } |
| 11603 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11604 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11605 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11606 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11607 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 11608 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 11609 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 11610 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 11611 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11612 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11613 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11614 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11615 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11616 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11617 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11618 | |
| 11619 | HttpRequestInfo request; |
| 11620 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11621 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11622 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11623 | request.traffic_annotation = |
| 11624 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11625 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 11626 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11627 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11628 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11629 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11630 | StaticSocketDataProvider data; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11631 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11632 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11633 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11634 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11635 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11636 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11637 | |
| 11638 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11639 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11640 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11641 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11642 | } |
| 11643 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11644 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11645 | class FakeUploadElementReader : public UploadElementReader { |
| 11646 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 11647 | FakeUploadElementReader() = default; |
| 11648 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11649 | |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11650 | CompletionOnceCallback TakeCallback() { return std::move(callback_); } |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11651 | |
| 11652 | // UploadElementReader overrides: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11653 | int Init(CompletionOnceCallback callback) override { |
| 11654 | callback_ = std::move(callback); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11655 | return ERR_IO_PENDING; |
| 11656 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11657 | uint64_t GetContentLength() const override { return 0; } |
| 11658 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11659 | int Read(IOBuffer* buf, |
| 11660 | int buf_length, |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11661 | CompletionOnceCallback callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11662 | return ERR_FAILED; |
| 11663 | } |
| 11664 | |
| 11665 | private: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11666 | CompletionOnceCallback callback_; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11667 | }; |
| 11668 | |
| 11669 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11670 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 11671 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11672 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11673 | |
| 11674 | HttpRequestInfo request; |
| 11675 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11676 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11677 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11678 | request.traffic_annotation = |
| 11679 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11680 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11681 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11682 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11683 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11684 | |
| 11685 | StaticSocketDataProvider data; |
| 11686 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11687 | |
| 11688 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11689 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11690 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 11691 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11692 | |
| 11693 | // Transaction is pending on request body initialization. |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11694 | CompletionOnceCallback init_callback = fake_reader->TakeCallback(); |
| 11695 | ASSERT_FALSE(init_callback.is_null()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11696 | |
| 11697 | // Return Init()'s result after the transaction gets destroyed. |
| 11698 | trans.reset(); |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11699 | std::move(init_callback).Run(OK); // Should not crash. |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11700 | } |
| 11701 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11702 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11703 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11704 | HttpRequestInfo request; |
| 11705 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11706 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11707 | request.traffic_annotation = |
| 11708 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11709 | |
| 11710 | // First transaction will request a resource and receive a Basic challenge |
| 11711 | // with realm="first_realm". |
| 11712 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11713 | MockWrite( |
| 11714 | "GET / HTTP/1.1\r\n" |
| 11715 | "Host: www.example.org\r\n" |
| 11716 | "Connection: keep-alive\r\n" |
| 11717 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11718 | }; |
| 11719 | MockRead data_reads1[] = { |
| 11720 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11721 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11722 | "\r\n"), |
| 11723 | }; |
| 11724 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11725 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11726 | // for first_realm. The server will reject and provide a challenge with |
| 11727 | // second_realm. |
| 11728 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11729 | MockWrite( |
| 11730 | "GET / HTTP/1.1\r\n" |
| 11731 | "Host: www.example.org\r\n" |
| 11732 | "Connection: keep-alive\r\n" |
| 11733 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 11734 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11735 | }; |
| 11736 | MockRead data_reads2[] = { |
| 11737 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11738 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 11739 | "\r\n"), |
| 11740 | }; |
| 11741 | |
| 11742 | // This again fails, and goes back to first_realm. Make sure that the |
| 11743 | // entry is removed from cache. |
| 11744 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11745 | MockWrite( |
| 11746 | "GET / HTTP/1.1\r\n" |
| 11747 | "Host: www.example.org\r\n" |
| 11748 | "Connection: keep-alive\r\n" |
| 11749 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 11750 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11751 | }; |
| 11752 | MockRead data_reads3[] = { |
| 11753 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11754 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11755 | "\r\n"), |
| 11756 | }; |
| 11757 | |
| 11758 | // Try one last time (with the correct password) and get the resource. |
| 11759 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11760 | MockWrite( |
| 11761 | "GET / HTTP/1.1\r\n" |
| 11762 | "Host: www.example.org\r\n" |
| 11763 | "Connection: keep-alive\r\n" |
| 11764 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 11765 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11766 | }; |
| 11767 | MockRead data_reads4[] = { |
| 11768 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11769 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11770 | "Content-Length: 5\r\n" |
| 11771 | "\r\n" |
| 11772 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11773 | }; |
| 11774 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11775 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 11776 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 11777 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
| 11778 | StaticSocketDataProvider data4(data_reads4, data_writes4); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11779 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 11780 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 11781 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 11782 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11783 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11784 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11785 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11786 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11787 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11788 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11789 | // Issue the first request with Authorize headers. There should be a |
| 11790 | // password prompt for first_realm waiting to be filled in after the |
| 11791 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11792 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11793 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11794 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11795 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11796 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11797 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11798 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11799 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11800 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11801 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11802 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11803 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11804 | |
| 11805 | // Issue the second request with an incorrect password. There should be a |
| 11806 | // password prompt for second_realm waiting to be filled in after the |
| 11807 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11808 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11809 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 11810 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11811 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11812 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11813 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11814 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11815 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11816 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11817 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11818 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11819 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11820 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11821 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11822 | |
| 11823 | // Issue the third request with another incorrect password. There should be |
| 11824 | // a password prompt for first_realm waiting to be filled in. If the password |
| 11825 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 11826 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11827 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11828 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 11829 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11830 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11831 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11832 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11833 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11834 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11835 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11836 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11837 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11838 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11839 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11840 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11841 | |
| 11842 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11843 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11844 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 11845 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11846 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11847 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11848 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11849 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11850 | ASSERT_TRUE(response); |
| 11851 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11852 | } |
| 11853 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11854 | // Regression test for https://crbug.com/754395. |
| 11855 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 11856 | MockRead data_reads[] = { |
| 11857 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11858 | MockRead(kAlternativeServiceHttpHeader), |
| 11859 | MockRead("\r\n"), |
| 11860 | MockRead("hello world"), |
| 11861 | MockRead(SYNCHRONOUS, OK), |
| 11862 | }; |
| 11863 | |
| 11864 | HttpRequestInfo request; |
| 11865 | request.method = "GET"; |
| 11866 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11867 | request.traffic_annotation = |
| 11868 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11869 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11870 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11871 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11872 | |
| 11873 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11874 | ssl.ssl_info.cert = |
| 11875 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11876 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 11877 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11878 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11879 | |
| 11880 | TestCompletionCallback callback; |
| 11881 | |
| 11882 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11883 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11884 | |
| 11885 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 11886 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11887 | |
| 11888 | url::SchemeHostPort test_server(request.url); |
| 11889 | HttpServerProperties* http_server_properties = |
| 11890 | session->http_server_properties(); |
| 11891 | EXPECT_TRUE( |
| 11892 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11893 | |
| 11894 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11895 | |
| 11896 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11897 | ASSERT_TRUE(response); |
| 11898 | ASSERT_TRUE(response->headers); |
| 11899 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11900 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11901 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 11902 | |
| 11903 | std::string response_data; |
| 11904 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11905 | EXPECT_EQ("hello world", response_data); |
| 11906 | |
| 11907 | EXPECT_TRUE( |
| 11908 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11909 | } |
| 11910 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11911 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11912 | MockRead data_reads[] = { |
| 11913 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11914 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11915 | MockRead("\r\n"), |
| 11916 | MockRead("hello world"), |
| 11917 | MockRead(SYNCHRONOUS, OK), |
| 11918 | }; |
| 11919 | |
| 11920 | HttpRequestInfo request; |
| 11921 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11922 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11923 | request.traffic_annotation = |
| 11924 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11925 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11926 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11927 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11928 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11929 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11930 | ssl.ssl_info.cert = |
| 11931 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11932 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11933 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11934 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11935 | TestCompletionCallback callback; |
| 11936 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11937 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11938 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11939 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11940 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11941 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11942 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11943 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11944 | HttpServerProperties* http_server_properties = |
| 11945 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11946 | EXPECT_TRUE( |
| 11947 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11948 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11949 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11950 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11951 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11952 | ASSERT_TRUE(response); |
| 11953 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11954 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11955 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11956 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11957 | |
| 11958 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11959 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11960 | EXPECT_EQ("hello world", response_data); |
| 11961 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11962 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 11963 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 11964 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 11965 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 11966 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11967 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11968 | } |
| 11969 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11970 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11971 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11972 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11973 | MockRead data_reads[] = { |
| 11974 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11975 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11976 | MockRead("\r\n"), |
| 11977 | MockRead("hello world"), |
| 11978 | MockRead(SYNCHRONOUS, OK), |
| 11979 | }; |
| 11980 | |
| 11981 | HttpRequestInfo request; |
| 11982 | request.method = "GET"; |
| 11983 | request.url = GURL("http://www.example.org/"); |
| 11984 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11985 | request.traffic_annotation = |
| 11986 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11987 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11988 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11989 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11990 | |
| 11991 | TestCompletionCallback callback; |
| 11992 | |
| 11993 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11994 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11995 | |
| 11996 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11997 | HttpServerProperties* http_server_properties = |
| 11998 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11999 | EXPECT_TRUE( |
| 12000 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12001 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12002 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12003 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12004 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12005 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12006 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12007 | ASSERT_TRUE(response); |
| 12008 | ASSERT_TRUE(response->headers); |
| 12009 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12010 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12011 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12012 | |
| 12013 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12014 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12015 | EXPECT_EQ("hello world", response_data); |
| 12016 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12017 | EXPECT_TRUE( |
| 12018 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12019 | } |
| 12020 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12021 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12022 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12023 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12024 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12025 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12026 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12027 | HttpRequestInfo request; |
| 12028 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12029 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12030 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12031 | request.traffic_annotation = |
| 12032 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12033 | |
| 12034 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12035 | StaticSocketDataProvider first_data; |
| 12036 | first_data.set_connect_data(mock_connect); |
| 12037 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12038 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12039 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12040 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12041 | |
| 12042 | MockRead data_reads[] = { |
| 12043 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12044 | MockRead(ASYNC, OK), |
| 12045 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12046 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12047 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12048 | |
| 12049 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12050 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12051 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12052 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12053 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 12054 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12055 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12056 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12057 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 12058 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12059 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12060 | TestCompletionCallback callback; |
| 12061 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12062 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12063 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12064 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12065 | } |
| 12066 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12067 | // Regression test for https://crbug.com/615497: |
| 12068 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12069 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12070 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12071 | HttpRequestInfo request; |
| 12072 | request.method = "GET"; |
| 12073 | request.url = GURL("http://www.example.org/"); |
| 12074 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12075 | request.traffic_annotation = |
| 12076 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12077 | |
| 12078 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12079 | StaticSocketDataProvider first_data; |
| 12080 | first_data.set_connect_data(mock_connect); |
| 12081 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 12082 | |
| 12083 | MockRead data_reads[] = { |
| 12084 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12085 | MockRead(ASYNC, OK), |
| 12086 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12087 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12088 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12089 | |
| 12090 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12091 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12092 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12093 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12094 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12095 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12096 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12097 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 12098 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12099 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12100 | TestCompletionCallback callback; |
| 12101 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12102 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12103 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12104 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12105 | } |
| 12106 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12107 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12108 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12109 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12110 | HttpServerProperties* http_server_properties = |
| 12111 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12112 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12113 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12114 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12115 | http_server_properties->SetQuicAlternativeService( |
| 12116 | test_server, alternative_service, expiration, |
| 12117 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12118 | EXPECT_EQ( |
| 12119 | 1u, |
| 12120 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12121 | |
| 12122 | // Send a clear header. |
| 12123 | MockRead data_reads[] = { |
| 12124 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12125 | MockRead("Alt-Svc: clear\r\n"), |
| 12126 | MockRead("\r\n"), |
| 12127 | MockRead("hello world"), |
| 12128 | MockRead(SYNCHRONOUS, OK), |
| 12129 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12130 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12131 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12132 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12133 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12134 | ssl.ssl_info.cert = |
| 12135 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12136 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12137 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12138 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12139 | HttpRequestInfo request; |
| 12140 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12141 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12142 | request.traffic_annotation = |
| 12143 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12144 | |
| 12145 | TestCompletionCallback callback; |
| 12146 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12147 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12148 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12149 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12150 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12151 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12152 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12153 | ASSERT_TRUE(response); |
| 12154 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12155 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12156 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12157 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12158 | |
| 12159 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12160 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12161 | EXPECT_EQ("hello world", response_data); |
| 12162 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12163 | EXPECT_TRUE( |
| 12164 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12165 | } |
| 12166 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12167 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12168 | MockRead data_reads[] = { |
| 12169 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12170 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 12171 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12172 | MockRead("hello world"), |
| 12173 | MockRead(SYNCHRONOUS, OK), |
| 12174 | }; |
| 12175 | |
| 12176 | HttpRequestInfo request; |
| 12177 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12178 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12179 | request.traffic_annotation = |
| 12180 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12181 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12182 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12183 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12184 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12185 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12186 | ssl.ssl_info.cert = |
| 12187 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12188 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12189 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12190 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12191 | TestCompletionCallback callback; |
| 12192 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12193 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12194 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12195 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12196 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12197 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12198 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12199 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12200 | HttpServerProperties* http_server_properties = |
| 12201 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12202 | EXPECT_TRUE( |
| 12203 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12204 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12205 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12206 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12207 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12208 | ASSERT_TRUE(response); |
| 12209 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12210 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12211 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12212 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12213 | |
| 12214 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12215 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12216 | EXPECT_EQ("hello world", response_data); |
| 12217 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12218 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 12219 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 12220 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 12221 | |
| 12222 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 12223 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12224 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12225 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 12226 | 1234); |
| 12227 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12228 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12229 | } |
| 12230 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12231 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12232 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12233 | HostPortPair alternative("alternative.example.org", 443); |
| 12234 | std::string origin_url = "https://origin.example.org:443"; |
| 12235 | std::string alternative_url = "https://alternative.example.org:443"; |
| 12236 | |
| 12237 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12238 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12239 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12240 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12241 | |
| 12242 | // HTTP/1.1 data for request. |
| 12243 | MockWrite http_writes[] = { |
| 12244 | MockWrite("GET / HTTP/1.1\r\n" |
| 12245 | "Host: alternative.example.org\r\n" |
| 12246 | "Connection: keep-alive\r\n\r\n"), |
| 12247 | }; |
| 12248 | |
| 12249 | MockRead http_reads[] = { |
| 12250 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12251 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12252 | "Content-Length: 40\r\n\r\n" |
| 12253 | "first HTTP/1.1 response from alternative"), |
| 12254 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12255 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12256 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12257 | |
| 12258 | StaticSocketDataProvider data_refused; |
| 12259 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12260 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12261 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12262 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12263 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12264 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12265 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12266 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12267 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12268 | http_server_properties->SetQuicAlternativeService( |
| 12269 | server, alternative_service, expiration, |
| 12270 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12271 | // Mark the QUIC alternative service as broken. |
| 12272 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 12273 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12274 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12275 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12276 | request.method = "GET"; |
| 12277 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12278 | request.traffic_annotation = |
| 12279 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12280 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12281 | TestCompletionCallback callback; |
| 12282 | NetErrorDetails details; |
| 12283 | EXPECT_FALSE(details.quic_broken); |
| 12284 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12285 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12286 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12287 | EXPECT_TRUE(details.quic_broken); |
| 12288 | } |
| 12289 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12290 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12291 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12292 | HostPortPair alternative1("alternative1.example.org", 443); |
| 12293 | HostPortPair alternative2("alternative2.example.org", 443); |
| 12294 | std::string origin_url = "https://origin.example.org:443"; |
| 12295 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 12296 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 12297 | |
| 12298 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 12299 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12300 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12301 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12302 | |
| 12303 | // HTTP/1.1 data for request. |
| 12304 | MockWrite http_writes[] = { |
| 12305 | MockWrite("GET / HTTP/1.1\r\n" |
| 12306 | "Host: alternative1.example.org\r\n" |
| 12307 | "Connection: keep-alive\r\n\r\n"), |
| 12308 | }; |
| 12309 | |
| 12310 | MockRead http_reads[] = { |
| 12311 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12312 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12313 | "Content-Length: 40\r\n\r\n" |
| 12314 | "first HTTP/1.1 response from alternative1"), |
| 12315 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12316 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12317 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12318 | |
| 12319 | StaticSocketDataProvider data_refused; |
| 12320 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12321 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12322 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12323 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12324 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12325 | session->http_server_properties(); |
| 12326 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12327 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12328 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 12329 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 12330 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12331 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12332 | alternative_service_info_vector.push_back( |
| 12333 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12334 | alternative_service1, expiration, |
| 12335 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12336 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12337 | alternative_service_info_vector.push_back( |
| 12338 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12339 | alternative_service2, expiration, |
| 12340 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12341 | |
| 12342 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12343 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12344 | |
| 12345 | // Mark one of the QUIC alternative service as broken. |
| 12346 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12347 | EXPECT_EQ(2u, |
| 12348 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12349 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12350 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12351 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12352 | request.method = "GET"; |
| 12353 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12354 | request.traffic_annotation = |
| 12355 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12356 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12357 | TestCompletionCallback callback; |
| 12358 | NetErrorDetails details; |
| 12359 | EXPECT_FALSE(details.quic_broken); |
| 12360 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12361 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12362 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12363 | EXPECT_FALSE(details.quic_broken); |
| 12364 | } |
| 12365 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12366 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12367 | HttpRequestInfo request; |
| 12368 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12369 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12370 | request.traffic_annotation = |
| 12371 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12372 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12373 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12374 | StaticSocketDataProvider first_data; |
| 12375 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12376 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12377 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12378 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12379 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12380 | |
| 12381 | MockRead data_reads[] = { |
| 12382 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12383 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12384 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12385 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12386 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12387 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12388 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12389 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12390 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12391 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12392 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12393 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12394 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 12395 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12396 | // Port is ignored by MockConnect anyway. |
| 12397 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12398 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12399 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12400 | http_server_properties->SetHttp2AlternativeService( |
| 12401 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12402 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12403 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12404 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12405 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12406 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12407 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12408 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12409 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12410 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12411 | ASSERT_TRUE(response); |
| 12412 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12413 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12414 | |
| 12415 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12416 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12417 | EXPECT_EQ("hello world", response_data); |
| 12418 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12419 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 12420 | http_server_properties->GetAlternativeServiceInfos(server); |
| 12421 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12422 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12423 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12424 | EXPECT_TRUE( |
| 12425 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12426 | } |
| 12427 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12428 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12429 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12430 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12431 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12432 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12433 | HttpRequestInfo restricted_port_request; |
| 12434 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12435 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12436 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12437 | restricted_port_request.traffic_annotation = |
| 12438 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12439 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12440 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12441 | StaticSocketDataProvider first_data; |
| 12442 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12443 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12444 | |
| 12445 | MockRead data_reads[] = { |
| 12446 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12447 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12448 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12449 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12450 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12451 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12452 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12453 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12454 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12455 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12456 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12457 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12458 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12459 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12460 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12461 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12462 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12463 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12464 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12465 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12466 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12467 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12468 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12469 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12470 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12471 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12472 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12473 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12474 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12475 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12476 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12477 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12478 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 12479 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 12480 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12481 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12482 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12483 | |
| 12484 | HttpRequestInfo restricted_port_request; |
| 12485 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12486 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12487 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12488 | restricted_port_request.traffic_annotation = |
| 12489 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12490 | |
| 12491 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12492 | StaticSocketDataProvider first_data; |
| 12493 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12494 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12495 | |
| 12496 | MockRead data_reads[] = { |
| 12497 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12498 | MockRead("hello world"), |
| 12499 | MockRead(ASYNC, OK), |
| 12500 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12501 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12502 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12503 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12504 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12505 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12506 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12507 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12508 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12509 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12510 | session->http_server_properties(); |
| 12511 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12512 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12513 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12514 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12515 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12516 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12517 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12518 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12519 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12520 | TestCompletionCallback callback; |
| 12521 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12522 | EXPECT_EQ(ERR_IO_PENDING, |
| 12523 | trans.Start(&restricted_port_request, callback.callback(), |
| 12524 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12525 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12526 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12527 | } |
| 12528 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12529 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12530 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12531 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12532 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12533 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12534 | HttpRequestInfo restricted_port_request; |
| 12535 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12536 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12537 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12538 | restricted_port_request.traffic_annotation = |
| 12539 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12540 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12541 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12542 | StaticSocketDataProvider first_data; |
| 12543 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12544 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12545 | |
| 12546 | MockRead data_reads[] = { |
| 12547 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12548 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12549 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12550 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12551 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12552 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12553 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12554 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12555 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12556 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12557 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12558 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12559 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12560 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12561 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12562 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12563 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12564 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12565 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12566 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12567 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12568 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12569 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12570 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12571 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12572 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12573 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12574 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12575 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12576 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12577 | } |
| 12578 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12579 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12580 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12581 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12582 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12583 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12584 | HttpRequestInfo unrestricted_port_request; |
| 12585 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12586 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12587 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12588 | unrestricted_port_request.traffic_annotation = |
| 12589 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12590 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12591 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12592 | StaticSocketDataProvider first_data; |
| 12593 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12594 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12595 | |
| 12596 | MockRead data_reads[] = { |
| 12597 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12598 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12599 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12600 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12601 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12602 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12603 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12604 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12605 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12606 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12607 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12608 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12609 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12610 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12611 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12612 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12613 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12614 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12615 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12616 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12617 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12618 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12619 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12620 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12621 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12622 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12623 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12624 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12625 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12626 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12627 | } |
| 12628 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12629 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12630 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12631 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12632 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12633 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12634 | HttpRequestInfo unrestricted_port_request; |
| 12635 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12636 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12637 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12638 | unrestricted_port_request.traffic_annotation = |
| 12639 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12640 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12641 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12642 | StaticSocketDataProvider first_data; |
| 12643 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12644 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12645 | |
| 12646 | MockRead data_reads[] = { |
| 12647 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12648 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12649 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12650 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12651 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12652 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12653 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12654 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12655 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12656 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12657 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12658 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12659 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12660 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 12661 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12662 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12663 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12664 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12665 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12666 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12667 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12668 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12669 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12670 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12671 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12672 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12673 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12674 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12675 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12676 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12677 | } |
| 12678 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12679 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
Xida Chen | 9bfe0b6 | 2018-04-24 19:52:21 | [diff] [blame] | 12680 | // to an unsafe port, and that we resume the second HttpStreamFactory::Job once |
| 12681 | // the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12682 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12683 | HttpRequestInfo request; |
| 12684 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12685 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12686 | request.traffic_annotation = |
| 12687 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12688 | |
| 12689 | // The alternate protocol request will error out before we attempt to connect, |
| 12690 | // so only the standard HTTP request will try to connect. |
| 12691 | MockRead data_reads[] = { |
| 12692 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12693 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12694 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12695 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12696 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12697 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12698 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12699 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12700 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12701 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12702 | session->http_server_properties(); |
| 12703 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12704 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12705 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12706 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12707 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12708 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12709 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12710 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12711 | TestCompletionCallback callback; |
| 12712 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12713 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12714 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12715 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12716 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12717 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12718 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12719 | ASSERT_TRUE(response); |
| 12720 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12721 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12722 | |
| 12723 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12724 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12725 | EXPECT_EQ("hello world", response_data); |
| 12726 | } |
| 12727 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12728 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12729 | HttpRequestInfo request; |
| 12730 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12731 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12732 | request.traffic_annotation = |
| 12733 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12734 | |
| 12735 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12736 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12737 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12738 | MockRead("\r\n"), |
| 12739 | MockRead("hello world"), |
| 12740 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12741 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12742 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12743 | StaticSocketDataProvider first_transaction(data_reads, |
| 12744 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12745 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12746 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12747 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12748 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12749 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12750 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12751 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12752 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12753 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12754 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12755 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12756 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 12757 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12758 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12759 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12760 | }; |
| 12761 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12762 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12763 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12764 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12765 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12766 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12767 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12768 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12769 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12770 | &hanging_non_alternate_protocol_socket); |
| 12771 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12772 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12773 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12774 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12775 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12776 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12777 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12778 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12779 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12780 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12781 | |
| 12782 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12783 | ASSERT_TRUE(response); |
| 12784 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12785 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12786 | |
| 12787 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12788 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12789 | EXPECT_EQ("hello world", response_data); |
| 12790 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12791 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12792 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12793 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12794 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12795 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12796 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12797 | |
| 12798 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12799 | ASSERT_TRUE(response); |
| 12800 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12801 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12802 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12803 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12804 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12805 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12806 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12807 | } |
| 12808 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12809 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12810 | HttpRequestInfo request; |
| 12811 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12812 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12813 | request.traffic_annotation = |
| 12814 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12815 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12816 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12817 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12818 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12819 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12820 | MockRead("\r\n"), |
| 12821 | MockRead("hello world"), |
| 12822 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12823 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12824 | }; |
| 12825 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12826 | StaticSocketDataProvider http11_data(data_reads, base::span<MockWrite>()); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12827 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12828 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12829 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12830 | ssl_http11.ssl_info.cert = |
| 12831 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12832 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12833 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 12834 | |
| 12835 | // Second transaction starts an alternative and a non-alternative Job. |
| 12836 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12837 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12838 | StaticSocketDataProvider hanging_socket1; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12839 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12840 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 12841 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12842 | StaticSocketDataProvider hanging_socket2; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12843 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 12844 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12845 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12846 | // Third transaction starts an alternative and a non-alternative job. |
| 12847 | // The non-alternative job hangs, but the alternative one succeeds. |
| 12848 | // The second transaction, still pending, binds to this socket. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12849 | spdy::SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12850 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12851 | spdy::SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12852 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12853 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12854 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12855 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12856 | spdy::SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 12857 | spdy::SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 12858 | spdy::SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 12859 | spdy::SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12860 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12861 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 12862 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12863 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12864 | }; |
| 12865 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12866 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12867 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12868 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12869 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12870 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12871 | StaticSocketDataProvider hanging_socket3; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12872 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 12873 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12874 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12875 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12876 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12877 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12878 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12879 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12880 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12881 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12882 | |
| 12883 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12884 | ASSERT_TRUE(response); |
| 12885 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12886 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12887 | |
| 12888 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12889 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12890 | EXPECT_EQ("hello world", response_data); |
| 12891 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12892 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12893 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12894 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12895 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12896 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12897 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12898 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12899 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12900 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12901 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12902 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 12903 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12904 | |
| 12905 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12906 | ASSERT_TRUE(response); |
| 12907 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12908 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12909 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12910 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12911 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12912 | EXPECT_EQ("hello!", response_data); |
| 12913 | |
| 12914 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12915 | ASSERT_TRUE(response); |
| 12916 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12917 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12918 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12919 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12920 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12921 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12922 | } |
| 12923 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12924 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
Bence Béky | bcae3709 | 2018-06-12 04:18:53 | [diff] [blame] | 12925 | session_deps_.host_resolver->set_synchronous_mode(true); |
| 12926 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12927 | HttpRequestInfo request; |
| 12928 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12929 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12930 | request.traffic_annotation = |
| 12931 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12932 | |
| 12933 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12934 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12935 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12936 | MockRead("\r\n"), |
| 12937 | MockRead("hello world"), |
| 12938 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12939 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12940 | }; |
| 12941 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12942 | StaticSocketDataProvider first_transaction(data_reads, |
| 12943 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12944 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12945 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12946 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12947 | ssl.ssl_info.cert = |
| 12948 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12949 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12950 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12951 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12952 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12953 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12954 | hanging_alternate_protocol_socket.set_connect_data( |
| 12955 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12956 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12957 | &hanging_alternate_protocol_socket); |
| 12958 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12959 | // 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] | 12960 | StaticSocketDataProvider second_transaction(data_reads, |
| 12961 | base::span<MockWrite>()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12962 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12963 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12964 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12965 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12966 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12967 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12968 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12969 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12970 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12971 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12972 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12973 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12974 | |
| 12975 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12976 | ASSERT_TRUE(response); |
| 12977 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12978 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12979 | |
| 12980 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12981 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12982 | EXPECT_EQ("hello world", response_data); |
| 12983 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12984 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12985 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12986 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12987 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12988 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12989 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12990 | |
| 12991 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12992 | ASSERT_TRUE(response); |
| 12993 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12994 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12995 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12996 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12997 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12998 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12999 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13000 | } |
| 13001 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13002 | // Test that proxy is resolved using the origin url, |
| 13003 | // regardless of the alternative server. |
| 13004 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 13005 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 13006 | ProxyConfig proxy_config; |
| 13007 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 13008 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13009 | auto proxy_config_service = std::make_unique<ProxyConfigServiceFixed>( |
| 13010 | ProxyConfigWithAnnotation(proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13011 | |
| 13012 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13013 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13014 | &capturing_proxy_resolver); |
| 13015 | |
| 13016 | TestNetLog net_log; |
| 13017 | |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 13018 | session_deps_.proxy_resolution_service = |
| 13019 | std::make_unique<ProxyResolutionService>( |
| 13020 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 13021 | &net_log); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13022 | |
| 13023 | session_deps_.net_log = &net_log; |
| 13024 | |
| 13025 | // Configure alternative service with a hostname that is not bypassed by the |
| 13026 | // proxy. |
| 13027 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13028 | HttpServerProperties* http_server_properties = |
| 13029 | session->http_server_properties(); |
| 13030 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13031 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13032 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13033 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13034 | http_server_properties->SetHttp2AlternativeService( |
| 13035 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13036 | |
| 13037 | // Non-alternative job should hang. |
| 13038 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13039 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13040 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 13041 | session_deps_.socket_factory->AddSocketDataProvider( |
| 13042 | &hanging_alternate_protocol_socket); |
| 13043 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13044 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13045 | |
| 13046 | HttpRequestInfo request; |
| 13047 | request.method = "GET"; |
| 13048 | request.url = GURL("https://www.example.org/"); |
| 13049 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13050 | request.traffic_annotation = |
| 13051 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13052 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13053 | spdy::SpdySerializedFrame req( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13054 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 13055 | |
| 13056 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 13057 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13058 | spdy::SpdySerializedFrame resp( |
| 13059 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13060 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13061 | MockRead spdy_reads[] = { |
| 13062 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 13063 | }; |
| 13064 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13065 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13066 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 13067 | |
| 13068 | TestCompletionCallback callback; |
| 13069 | |
| 13070 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13071 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13072 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13073 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 13074 | |
| 13075 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 13076 | ASSERT_TRUE(response); |
| 13077 | ASSERT_TRUE(response->headers); |
| 13078 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13079 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13080 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13081 | |
| 13082 | std::string response_data; |
| 13083 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 13084 | EXPECT_EQ("hello!", response_data); |
| 13085 | |
| 13086 | // Origin host bypasses proxy, no resolution should have happened. |
| 13087 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 13088 | } |
| 13089 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13090 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13091 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13092 | proxy_config.set_auto_detect(true); |
| 13093 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 13094 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13095 | CapturingProxyResolver capturing_proxy_resolver; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13096 | session_deps_.proxy_resolution_service = |
| 13097 | std::make_unique<ProxyResolutionService>( |
| 13098 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 13099 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 13100 | std::make_unique<CapturingProxyResolverFactory>( |
| 13101 | &capturing_proxy_resolver), |
| 13102 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13103 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13104 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13105 | |
| 13106 | HttpRequestInfo request; |
| 13107 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13108 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13109 | request.traffic_annotation = |
| 13110 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13111 | |
| 13112 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13113 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13114 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13115 | MockRead("\r\n"), |
| 13116 | MockRead("hello world"), |
| 13117 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13118 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13119 | }; |
| 13120 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13121 | StaticSocketDataProvider first_transaction(data_reads, |
| 13122 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13123 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13124 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13125 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13126 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13127 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13128 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13129 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13130 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13131 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13132 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13133 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13134 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13135 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13136 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13137 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13138 | }; |
| 13139 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13140 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 13141 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13142 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 13143 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13144 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13145 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 13146 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13147 | }; |
| 13148 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13149 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13150 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13151 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13152 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13153 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13154 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 13155 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13156 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13157 | &hanging_non_alternate_protocol_socket); |
| 13158 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13159 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13160 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13161 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13162 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13163 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13164 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13165 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13166 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13167 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 13168 | |
| 13169 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13170 | ASSERT_TRUE(response); |
| 13171 | ASSERT_TRUE(response->headers); |
| 13172 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 13173 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13174 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13175 | |
| 13176 | std::string response_data; |
| 13177 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 13178 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13179 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13180 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13181 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13182 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13183 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13184 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13185 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13186 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13187 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13188 | ASSERT_TRUE(response); |
| 13189 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13190 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13191 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13192 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13193 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13194 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13195 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13196 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 13197 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13198 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13199 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13200 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13201 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13202 | LoadTimingInfo load_timing_info; |
| 13203 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 13204 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13205 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13206 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13207 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13208 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 13209 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13210 | HttpRequestInfo request; |
| 13211 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13212 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13213 | request.traffic_annotation = |
| 13214 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13215 | |
| 13216 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13217 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13218 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13219 | MockRead("\r\n"), |
| 13220 | MockRead("hello world"), |
| 13221 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13222 | }; |
| 13223 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13224 | StaticSocketDataProvider first_transaction(data_reads, |
| 13225 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13226 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13227 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13228 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13229 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13230 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13231 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13232 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13233 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13234 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13235 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13236 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13237 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 13238 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13239 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13240 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13241 | }; |
| 13242 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13243 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13244 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13245 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 13246 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13247 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13248 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13249 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13250 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13251 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13252 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13253 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13254 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13255 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13256 | |
| 13257 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13258 | ASSERT_TRUE(response); |
| 13259 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13260 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13261 | |
| 13262 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13263 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13264 | EXPECT_EQ("hello world", response_data); |
| 13265 | |
| 13266 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13267 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13268 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 13269 | PRIVACY_MODE_DISABLED, |
| 13270 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13271 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 13272 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 13273 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13274 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13275 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13276 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13277 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13278 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13279 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13280 | |
| 13281 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13282 | ASSERT_TRUE(response); |
| 13283 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13284 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13285 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13286 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13287 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13288 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13289 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13290 | } |
| 13291 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13292 | // GenerateAuthToken is a mighty big test. |
| 13293 | // It tests all permutation of GenerateAuthToken behavior: |
| 13294 | // - Synchronous and Asynchronous completion. |
| 13295 | // - OK or error on completion. |
| 13296 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 13297 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 13298 | // - Non-authenticating and authenticating backend. |
| 13299 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 13300 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13301 | // problems generating an auth token for an authenticating proxy, we don't |
| 13302 | // need to test all permutations of the backend server). |
| 13303 | // |
| 13304 | // The test proceeds by going over each of the configuration cases, and |
| 13305 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 13306 | // specifies both the configuration for the test as well as the expectations |
| 13307 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13308 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13309 | static const char kServer[] = "http://www.example.com"; |
| 13310 | static const char kSecureServer[] = "https://www.example.com"; |
| 13311 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13312 | |
| 13313 | enum AuthTiming { |
| 13314 | AUTH_NONE, |
| 13315 | AUTH_SYNC, |
| 13316 | AUTH_ASYNC, |
| 13317 | }; |
| 13318 | |
| 13319 | const MockWrite kGet( |
| 13320 | "GET / HTTP/1.1\r\n" |
| 13321 | "Host: www.example.com\r\n" |
| 13322 | "Connection: keep-alive\r\n\r\n"); |
| 13323 | const MockWrite kGetProxy( |
| 13324 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13325 | "Host: www.example.com\r\n" |
| 13326 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13327 | const MockWrite kGetAuth( |
| 13328 | "GET / HTTP/1.1\r\n" |
| 13329 | "Host: www.example.com\r\n" |
| 13330 | "Connection: keep-alive\r\n" |
| 13331 | "Authorization: auth_token\r\n\r\n"); |
| 13332 | const MockWrite kGetProxyAuth( |
| 13333 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13334 | "Host: www.example.com\r\n" |
| 13335 | "Proxy-Connection: keep-alive\r\n" |
| 13336 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13337 | const MockWrite kGetAuthThroughProxy( |
| 13338 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13339 | "Host: www.example.com\r\n" |
| 13340 | "Proxy-Connection: keep-alive\r\n" |
| 13341 | "Authorization: auth_token\r\n\r\n"); |
| 13342 | const MockWrite kGetAuthWithProxyAuth( |
| 13343 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13344 | "Host: www.example.com\r\n" |
| 13345 | "Proxy-Connection: keep-alive\r\n" |
| 13346 | "Proxy-Authorization: auth_token\r\n" |
| 13347 | "Authorization: auth_token\r\n\r\n"); |
| 13348 | const MockWrite kConnect( |
| 13349 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13350 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13351 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13352 | const MockWrite kConnectProxyAuth( |
| 13353 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13354 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13355 | "Proxy-Connection: keep-alive\r\n" |
| 13356 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13357 | |
| 13358 | const MockRead kSuccess( |
| 13359 | "HTTP/1.1 200 OK\r\n" |
| 13360 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13361 | "Content-Length: 3\r\n\r\n" |
| 13362 | "Yes"); |
| 13363 | const MockRead kFailure( |
| 13364 | "Should not be called."); |
| 13365 | const MockRead kServerChallenge( |
| 13366 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13367 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13368 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13369 | "Content-Length: 14\r\n\r\n" |
| 13370 | "Unauthorized\r\n"); |
| 13371 | const MockRead kProxyChallenge( |
| 13372 | "HTTP/1.1 407 Unauthorized\r\n" |
| 13373 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 13374 | "Proxy-Connection: close\r\n" |
| 13375 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13376 | "Content-Length: 14\r\n\r\n" |
| 13377 | "Unauthorized\r\n"); |
| 13378 | const MockRead kProxyConnected( |
| 13379 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 13380 | |
| 13381 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 13382 | // no constructors, but the C++ compiler on Windows warns about |
| 13383 | // unspecified data in compound literals. So, moved to using constructors, |
| 13384 | // and TestRound's created with the default constructor should not be used. |
| 13385 | struct TestRound { |
| 13386 | TestRound() |
| 13387 | : expected_rv(ERR_UNEXPECTED), |
| 13388 | extra_write(NULL), |
| 13389 | extra_read(NULL) { |
| 13390 | } |
| 13391 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 13392 | int expected_rv_arg) |
| 13393 | : write(write_arg), |
| 13394 | read(read_arg), |
| 13395 | expected_rv(expected_rv_arg), |
| 13396 | extra_write(NULL), |
| 13397 | extra_read(NULL) { |
| 13398 | } |
| 13399 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 13400 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 13401 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13402 | : write(write_arg), |
| 13403 | read(read_arg), |
| 13404 | expected_rv(expected_rv_arg), |
| 13405 | extra_write(extra_write_arg), |
| 13406 | extra_read(extra_read_arg) { |
| 13407 | } |
| 13408 | MockWrite write; |
| 13409 | MockRead read; |
| 13410 | int expected_rv; |
| 13411 | const MockWrite* extra_write; |
| 13412 | const MockRead* extra_read; |
| 13413 | }; |
| 13414 | |
| 13415 | static const int kNoSSL = 500; |
| 13416 | |
| 13417 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13418 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13419 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13420 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13421 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13422 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13423 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13424 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13425 | int num_auth_rounds; |
| 13426 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13427 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13428 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13429 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13430 | {__LINE__, |
| 13431 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13432 | AUTH_NONE, |
| 13433 | OK, |
| 13434 | kServer, |
| 13435 | AUTH_NONE, |
| 13436 | OK, |
| 13437 | 1, |
| 13438 | kNoSSL, |
| 13439 | {TestRound(kGet, kSuccess, OK)}}, |
| 13440 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13441 | {__LINE__, |
| 13442 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13443 | AUTH_NONE, |
| 13444 | OK, |
| 13445 | kServer, |
| 13446 | AUTH_SYNC, |
| 13447 | OK, |
| 13448 | 2, |
| 13449 | kNoSSL, |
| 13450 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13451 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13452 | {__LINE__, |
| 13453 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13454 | AUTH_NONE, |
| 13455 | OK, |
| 13456 | kServer, |
| 13457 | AUTH_SYNC, |
| 13458 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13459 | 3, |
| 13460 | kNoSSL, |
| 13461 | {TestRound(kGet, kServerChallenge, OK), |
| 13462 | TestRound(kGet, kServerChallenge, OK), |
| 13463 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13464 | {__LINE__, |
| 13465 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13466 | AUTH_NONE, |
| 13467 | OK, |
| 13468 | kServer, |
| 13469 | AUTH_SYNC, |
| 13470 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13471 | 2, |
| 13472 | kNoSSL, |
| 13473 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13474 | {__LINE__, |
| 13475 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13476 | AUTH_NONE, |
| 13477 | OK, |
| 13478 | kServer, |
| 13479 | AUTH_SYNC, |
| 13480 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 13481 | 2, |
| 13482 | kNoSSL, |
| 13483 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13484 | {__LINE__, |
| 13485 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13486 | AUTH_SYNC, |
| 13487 | ERR_FAILED, |
| 13488 | kServer, |
| 13489 | AUTH_NONE, |
| 13490 | OK, |
| 13491 | 2, |
| 13492 | kNoSSL, |
| 13493 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13494 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13495 | {__LINE__, |
| 13496 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13497 | AUTH_ASYNC, |
| 13498 | ERR_FAILED, |
| 13499 | kServer, |
| 13500 | AUTH_NONE, |
| 13501 | OK, |
| 13502 | 2, |
| 13503 | kNoSSL, |
| 13504 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13505 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13506 | {__LINE__, |
| 13507 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13508 | AUTH_NONE, |
| 13509 | OK, |
| 13510 | kServer, |
| 13511 | AUTH_SYNC, |
| 13512 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13513 | 2, |
| 13514 | kNoSSL, |
| 13515 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13516 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13517 | {__LINE__, |
| 13518 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13519 | AUTH_NONE, |
| 13520 | OK, |
| 13521 | kServer, |
| 13522 | AUTH_ASYNC, |
| 13523 | ERR_FAILED, |
| 13524 | 2, |
| 13525 | kNoSSL, |
| 13526 | {TestRound(kGet, kServerChallenge, OK), |
| 13527 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13528 | {__LINE__, |
| 13529 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13530 | AUTH_NONE, |
| 13531 | OK, |
| 13532 | kServer, |
| 13533 | AUTH_ASYNC, |
| 13534 | OK, |
| 13535 | 2, |
| 13536 | kNoSSL, |
| 13537 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13538 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13539 | {__LINE__, |
| 13540 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13541 | AUTH_NONE, |
| 13542 | OK, |
| 13543 | kServer, |
| 13544 | AUTH_ASYNC, |
| 13545 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13546 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13547 | kNoSSL, |
| 13548 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13549 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 13550 | TestRound(kGet, kServerChallenge, OK), |
| 13551 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13552 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13553 | {__LINE__, |
| 13554 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13555 | AUTH_NONE, |
| 13556 | OK, |
| 13557 | kServer, |
| 13558 | AUTH_NONE, |
| 13559 | OK, |
| 13560 | 1, |
| 13561 | kNoSSL, |
| 13562 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 13563 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13564 | {__LINE__, |
| 13565 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13566 | AUTH_NONE, |
| 13567 | OK, |
| 13568 | kServer, |
| 13569 | AUTH_SYNC, |
| 13570 | OK, |
| 13571 | 2, |
| 13572 | kNoSSL, |
| 13573 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13574 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13575 | {__LINE__, |
| 13576 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13577 | AUTH_NONE, |
| 13578 | OK, |
| 13579 | kServer, |
| 13580 | AUTH_SYNC, |
| 13581 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13582 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13583 | kNoSSL, |
| 13584 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13585 | TestRound(kGetProxy, kServerChallenge, OK), |
| 13586 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13587 | {__LINE__, |
| 13588 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13589 | AUTH_NONE, |
| 13590 | OK, |
| 13591 | kServer, |
| 13592 | AUTH_ASYNC, |
| 13593 | OK, |
| 13594 | 2, |
| 13595 | kNoSSL, |
| 13596 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13597 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13598 | {__LINE__, |
| 13599 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13600 | AUTH_NONE, |
| 13601 | OK, |
| 13602 | kServer, |
| 13603 | AUTH_ASYNC, |
| 13604 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13605 | 2, |
| 13606 | kNoSSL, |
| 13607 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13608 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13609 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13610 | {__LINE__, |
| 13611 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13612 | AUTH_SYNC, |
| 13613 | OK, |
| 13614 | kServer, |
| 13615 | AUTH_NONE, |
| 13616 | OK, |
| 13617 | 2, |
| 13618 | kNoSSL, |
| 13619 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13620 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13621 | {__LINE__, |
| 13622 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13623 | AUTH_SYNC, |
| 13624 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13625 | kServer, |
| 13626 | AUTH_NONE, |
| 13627 | OK, |
| 13628 | 2, |
| 13629 | kNoSSL, |
| 13630 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13631 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13632 | {__LINE__, |
| 13633 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13634 | AUTH_ASYNC, |
| 13635 | OK, |
| 13636 | kServer, |
| 13637 | AUTH_NONE, |
| 13638 | OK, |
| 13639 | 2, |
| 13640 | kNoSSL, |
| 13641 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13642 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13643 | {__LINE__, |
| 13644 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13645 | AUTH_ASYNC, |
| 13646 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13647 | kServer, |
| 13648 | AUTH_NONE, |
| 13649 | OK, |
| 13650 | 2, |
| 13651 | kNoSSL, |
| 13652 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13653 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13654 | {__LINE__, |
| 13655 | kProxy, |
| 13656 | AUTH_ASYNC, |
| 13657 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13658 | kServer, |
| 13659 | AUTH_NONE, |
| 13660 | OK, |
| 13661 | 3, |
| 13662 | kNoSSL, |
| 13663 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13664 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13665 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13666 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13667 | {__LINE__, |
| 13668 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13669 | AUTH_SYNC, |
| 13670 | OK, |
| 13671 | kServer, |
| 13672 | AUTH_SYNC, |
| 13673 | OK, |
| 13674 | 3, |
| 13675 | kNoSSL, |
| 13676 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13677 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13678 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13679 | {__LINE__, |
| 13680 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13681 | AUTH_SYNC, |
| 13682 | OK, |
| 13683 | kServer, |
| 13684 | AUTH_SYNC, |
| 13685 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13686 | 3, |
| 13687 | kNoSSL, |
| 13688 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13689 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13690 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13691 | {__LINE__, |
| 13692 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13693 | AUTH_ASYNC, |
| 13694 | OK, |
| 13695 | kServer, |
| 13696 | AUTH_SYNC, |
| 13697 | OK, |
| 13698 | 3, |
| 13699 | kNoSSL, |
| 13700 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13701 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13702 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13703 | {__LINE__, |
| 13704 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13705 | AUTH_ASYNC, |
| 13706 | OK, |
| 13707 | kServer, |
| 13708 | AUTH_SYNC, |
| 13709 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13710 | 3, |
| 13711 | kNoSSL, |
| 13712 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13713 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13714 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13715 | {__LINE__, |
| 13716 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13717 | AUTH_SYNC, |
| 13718 | OK, |
| 13719 | kServer, |
| 13720 | AUTH_ASYNC, |
| 13721 | OK, |
| 13722 | 3, |
| 13723 | kNoSSL, |
| 13724 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13725 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13726 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13727 | {__LINE__, |
| 13728 | kProxy, |
| 13729 | AUTH_SYNC, |
| 13730 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13731 | kServer, |
| 13732 | AUTH_ASYNC, |
| 13733 | OK, |
| 13734 | 4, |
| 13735 | kNoSSL, |
| 13736 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13737 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13738 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13739 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 13740 | {__LINE__, |
| 13741 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13742 | AUTH_SYNC, |
| 13743 | OK, |
| 13744 | kServer, |
| 13745 | AUTH_ASYNC, |
| 13746 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13747 | 3, |
| 13748 | kNoSSL, |
| 13749 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13750 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13751 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13752 | {__LINE__, |
| 13753 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13754 | AUTH_ASYNC, |
| 13755 | OK, |
| 13756 | kServer, |
| 13757 | AUTH_ASYNC, |
| 13758 | OK, |
| 13759 | 3, |
| 13760 | kNoSSL, |
| 13761 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13762 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13763 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13764 | {__LINE__, |
| 13765 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13766 | AUTH_ASYNC, |
| 13767 | OK, |
| 13768 | kServer, |
| 13769 | AUTH_ASYNC, |
| 13770 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13771 | 3, |
| 13772 | kNoSSL, |
| 13773 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13774 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13775 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13776 | {__LINE__, |
| 13777 | kProxy, |
| 13778 | AUTH_ASYNC, |
| 13779 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13780 | kServer, |
| 13781 | AUTH_ASYNC, |
| 13782 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13783 | 4, |
| 13784 | kNoSSL, |
| 13785 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13786 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13787 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13788 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13789 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13790 | {__LINE__, |
| 13791 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13792 | AUTH_NONE, |
| 13793 | OK, |
| 13794 | kSecureServer, |
| 13795 | AUTH_NONE, |
| 13796 | OK, |
| 13797 | 1, |
| 13798 | 0, |
| 13799 | {TestRound(kGet, kSuccess, OK)}}, |
| 13800 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13801 | {__LINE__, |
| 13802 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13803 | AUTH_NONE, |
| 13804 | OK, |
| 13805 | kSecureServer, |
| 13806 | AUTH_SYNC, |
| 13807 | OK, |
| 13808 | 2, |
| 13809 | 0, |
| 13810 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13811 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13812 | {__LINE__, |
| 13813 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13814 | AUTH_NONE, |
| 13815 | OK, |
| 13816 | kSecureServer, |
| 13817 | AUTH_SYNC, |
| 13818 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13819 | 2, |
| 13820 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13821 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13822 | {__LINE__, |
| 13823 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13824 | AUTH_NONE, |
| 13825 | OK, |
| 13826 | kSecureServer, |
| 13827 | AUTH_ASYNC, |
| 13828 | OK, |
| 13829 | 2, |
| 13830 | 0, |
| 13831 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13832 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13833 | {__LINE__, |
| 13834 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13835 | AUTH_NONE, |
| 13836 | OK, |
| 13837 | kSecureServer, |
| 13838 | AUTH_ASYNC, |
| 13839 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13840 | 2, |
| 13841 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13842 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13843 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13844 | {__LINE__, |
| 13845 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13846 | AUTH_NONE, |
| 13847 | OK, |
| 13848 | kSecureServer, |
| 13849 | AUTH_NONE, |
| 13850 | OK, |
| 13851 | 1, |
| 13852 | 0, |
| 13853 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 13854 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13855 | {__LINE__, |
| 13856 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13857 | AUTH_NONE, |
| 13858 | OK, |
| 13859 | kSecureServer, |
| 13860 | AUTH_SYNC, |
| 13861 | OK, |
| 13862 | 2, |
| 13863 | 0, |
| 13864 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13865 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13866 | {__LINE__, |
| 13867 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13868 | AUTH_NONE, |
| 13869 | OK, |
| 13870 | kSecureServer, |
| 13871 | AUTH_SYNC, |
| 13872 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13873 | 2, |
| 13874 | 0, |
| 13875 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13876 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13877 | {__LINE__, |
| 13878 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13879 | AUTH_NONE, |
| 13880 | OK, |
| 13881 | kSecureServer, |
| 13882 | AUTH_ASYNC, |
| 13883 | OK, |
| 13884 | 2, |
| 13885 | 0, |
| 13886 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13887 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13888 | {__LINE__, |
| 13889 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13890 | AUTH_NONE, |
| 13891 | OK, |
| 13892 | kSecureServer, |
| 13893 | AUTH_ASYNC, |
| 13894 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13895 | 2, |
| 13896 | 0, |
| 13897 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13898 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13899 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13900 | {__LINE__, |
| 13901 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13902 | AUTH_SYNC, |
| 13903 | OK, |
| 13904 | kSecureServer, |
| 13905 | AUTH_NONE, |
| 13906 | OK, |
| 13907 | 2, |
| 13908 | 1, |
| 13909 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13910 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13911 | {__LINE__, |
| 13912 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13913 | AUTH_SYNC, |
| 13914 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13915 | kSecureServer, |
| 13916 | AUTH_NONE, |
| 13917 | OK, |
| 13918 | 2, |
| 13919 | kNoSSL, |
| 13920 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13921 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13922 | {__LINE__, |
| 13923 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13924 | AUTH_SYNC, |
| 13925 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13926 | kSecureServer, |
| 13927 | AUTH_NONE, |
| 13928 | OK, |
| 13929 | 2, |
| 13930 | kNoSSL, |
| 13931 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13932 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13933 | {__LINE__, |
| 13934 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13935 | AUTH_SYNC, |
| 13936 | ERR_UNEXPECTED, |
| 13937 | kSecureServer, |
| 13938 | AUTH_NONE, |
| 13939 | OK, |
| 13940 | 2, |
| 13941 | kNoSSL, |
| 13942 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13943 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13944 | {__LINE__, |
| 13945 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13946 | AUTH_ASYNC, |
| 13947 | OK, |
| 13948 | kSecureServer, |
| 13949 | AUTH_NONE, |
| 13950 | OK, |
| 13951 | 2, |
| 13952 | 1, |
| 13953 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13954 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13955 | {__LINE__, |
| 13956 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13957 | AUTH_ASYNC, |
| 13958 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13959 | kSecureServer, |
| 13960 | AUTH_NONE, |
| 13961 | OK, |
| 13962 | 2, |
| 13963 | kNoSSL, |
| 13964 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13965 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13966 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13967 | {__LINE__, |
| 13968 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13969 | AUTH_SYNC, |
| 13970 | OK, |
| 13971 | kSecureServer, |
| 13972 | AUTH_SYNC, |
| 13973 | OK, |
| 13974 | 3, |
| 13975 | 1, |
| 13976 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13977 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13978 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13979 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13980 | {__LINE__, |
| 13981 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13982 | AUTH_SYNC, |
| 13983 | OK, |
| 13984 | kSecureServer, |
| 13985 | AUTH_SYNC, |
| 13986 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13987 | 3, |
| 13988 | 1, |
| 13989 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13990 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13991 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13992 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13993 | {__LINE__, |
| 13994 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13995 | AUTH_ASYNC, |
| 13996 | OK, |
| 13997 | kSecureServer, |
| 13998 | AUTH_SYNC, |
| 13999 | OK, |
| 14000 | 3, |
| 14001 | 1, |
| 14002 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14003 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14004 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14005 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14006 | {__LINE__, |
| 14007 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14008 | AUTH_ASYNC, |
| 14009 | OK, |
| 14010 | kSecureServer, |
| 14011 | AUTH_SYNC, |
| 14012 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14013 | 3, |
| 14014 | 1, |
| 14015 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14016 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14017 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14018 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14019 | {__LINE__, |
| 14020 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14021 | AUTH_SYNC, |
| 14022 | OK, |
| 14023 | kSecureServer, |
| 14024 | AUTH_ASYNC, |
| 14025 | OK, |
| 14026 | 3, |
| 14027 | 1, |
| 14028 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14029 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14030 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14031 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14032 | {__LINE__, |
| 14033 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14034 | AUTH_SYNC, |
| 14035 | OK, |
| 14036 | kSecureServer, |
| 14037 | AUTH_ASYNC, |
| 14038 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14039 | 3, |
| 14040 | 1, |
| 14041 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14042 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14043 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14044 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14045 | {__LINE__, |
| 14046 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14047 | AUTH_ASYNC, |
| 14048 | OK, |
| 14049 | kSecureServer, |
| 14050 | AUTH_ASYNC, |
| 14051 | OK, |
| 14052 | 3, |
| 14053 | 1, |
| 14054 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14055 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14056 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14057 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14058 | {__LINE__, |
| 14059 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14060 | AUTH_ASYNC, |
| 14061 | OK, |
| 14062 | kSecureServer, |
| 14063 | AUTH_ASYNC, |
| 14064 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14065 | 3, |
| 14066 | 1, |
| 14067 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14068 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14069 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14070 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14071 | {__LINE__, |
| 14072 | kProxy, |
| 14073 | AUTH_ASYNC, |
| 14074 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14075 | kSecureServer, |
| 14076 | AUTH_ASYNC, |
| 14077 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14078 | 4, |
| 14079 | 2, |
| 14080 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14081 | TestRound(kConnect, kProxyChallenge, OK), |
| 14082 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14083 | &kServerChallenge), |
| 14084 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14085 | }; |
| 14086 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14087 | for (const auto& test_config : test_configs) { |
| 14088 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 14089 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14090 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14091 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14092 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14093 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14094 | |
| 14095 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14096 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14097 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14098 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14099 | std::string auth_challenge = "Mock realm=proxy"; |
| 14100 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14101 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14102 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14103 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14104 | empty_ssl_info, origin, |
| 14105 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14106 | auth_handler->SetGenerateExpectation( |
| 14107 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14108 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14109 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 14110 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14111 | } |
| 14112 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 14113 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14114 | std::string auth_challenge = "Mock realm=server"; |
| 14115 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14116 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14117 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14118 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14119 | empty_ssl_info, origin, |
| 14120 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14121 | auth_handler->SetGenerateExpectation( |
| 14122 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14123 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14124 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14125 | |
| 14126 | // The second handler always succeeds. It should only be used where there |
| 14127 | // are multiple auth sessions for server auth in the same network |
| 14128 | // transaction using the same auth scheme. |
| 14129 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14130 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14131 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 14132 | empty_ssl_info, origin, |
| 14133 | NetLogWithSource()); |
| 14134 | second_handler->SetGenerateExpectation(true, OK); |
| 14135 | auth_factory->AddMockHandler(second_handler.release(), |
| 14136 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14137 | } |
| 14138 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14139 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14140 | ProxyResolutionService::CreateFixed(test_config.proxy_url, |
| 14141 | TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14142 | } else { |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14143 | session_deps_.proxy_resolution_service = |
| 14144 | ProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14145 | } |
| 14146 | |
| 14147 | HttpRequestInfo request; |
| 14148 | request.method = "GET"; |
| 14149 | request.url = GURL(test_config.server_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14150 | request.traffic_annotation = |
| 14151 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14152 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14153 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14154 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14155 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 14156 | |
| 14157 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 14158 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14159 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14160 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14161 | const TestRound& read_write_round = test_config.rounds[round]; |
| 14162 | |
| 14163 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14164 | mock_reads.back().push_back(read_write_round.read); |
| 14165 | mock_writes.back().push_back(read_write_round.write); |
| 14166 | |
| 14167 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 14168 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 14169 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14170 | mock_reads.push_back(std::vector<MockRead>()); |
| 14171 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14172 | } |
| 14173 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14174 | if (read_write_round.extra_read) { |
| 14175 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14176 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14177 | if (read_write_round.extra_write) { |
| 14178 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 14179 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14180 | |
| 14181 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14182 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14183 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14184 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14185 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14186 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14187 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14188 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14189 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14190 | mock_reads[i], mock_writes[i])); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14191 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 14192 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14193 | } |
| 14194 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 14195 | // Transaction must be created after DataProviders, so it's destroyed before |
| 14196 | // they are as well. |
| 14197 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 14198 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14199 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14200 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14201 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14202 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14203 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14204 | int rv; |
| 14205 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14206 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14207 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14208 | rv = trans.RestartWithAuth( |
| 14209 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14210 | } |
| 14211 | if (rv == ERR_IO_PENDING) |
| 14212 | rv = callback.WaitForResult(); |
| 14213 | |
| 14214 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14215 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14216 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 14217 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14218 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 14219 | continue; |
| 14220 | } |
| 14221 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14222 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14223 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14224 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14225 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14226 | } |
| 14227 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 14228 | } |
| 14229 | } |
| 14230 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14231 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14232 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14233 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14234 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14235 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14236 | session_deps_.proxy_resolution_service = |
| 14237 | ProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14238 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14239 | |
| 14240 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14241 | auth_handler->set_connection_based(true); |
| 14242 | std::string auth_challenge = "Mock realm=server"; |
| 14243 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14244 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14245 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14246 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14247 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14248 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14249 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14250 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14251 | int rv = OK; |
| 14252 | const HttpResponseInfo* response = NULL; |
| 14253 | HttpRequestInfo request; |
| 14254 | request.method = "GET"; |
| 14255 | request.url = origin; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14256 | request.traffic_annotation = |
| 14257 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14258 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14259 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14260 | |
| 14261 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 14262 | // to validate that the TCP socket is not released to the pool between |
| 14263 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14264 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14265 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
Tarun Bansal | a763509 | 2019-02-20 10:00:59 | [diff] [blame] | 14266 | 50, // Max sockets for pool |
| 14267 | 1, // Max sockets per group |
| 14268 | base::TimeDelta::FromSeconds(10), // unused_idle_socket_timeout |
Matt Menke | cb77b540 | 2019-01-28 17:11:23 | [diff] [blame] | 14269 | session_deps_.socket_factory.get(), session_deps_.host_resolver.get(), |
Matt Menke | 1751ba7 | 2019-02-09 02:23:46 | [diff] [blame] | 14270 | nullptr /* proxy_delegate */, session_deps_.cert_verifier.get(), |
| 14271 | session_deps_.channel_id_service.get(), |
Matt Menke | cb77b540 | 2019-01-28 17:11:23 | [diff] [blame] | 14272 | session_deps_.transport_security_state.get(), |
| 14273 | session_deps_.cert_transparency_verifier.get(), |
| 14274 | session_deps_.ct_policy_enforcer.get(), |
Matt Menke | c94d97b | 2019-02-01 19:28:28 | [diff] [blame] | 14275 | nullptr /* ssl_client_session_cache */, |
Daniel McArdle | da3fa94 | 2019-02-15 16:41:21 | [diff] [blame] | 14276 | nullptr /* ssl_client_session_cache_privacy_mode */, |
Matt Menke | fa9574f | 2019-01-28 18:55:27 | [diff] [blame] | 14277 | session_deps_.ssl_config_service.get(), |
Matt Menke | cb77b540 | 2019-01-28 17:11:23 | [diff] [blame] | 14278 | nullptr /* socket_performance_watcher_factory */, |
| 14279 | nullptr /* network_quality_estimator */, session_deps_.net_log); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14280 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 14281 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14282 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14283 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14284 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14285 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14286 | |
| 14287 | const MockWrite kGet( |
| 14288 | "GET / HTTP/1.1\r\n" |
| 14289 | "Host: www.example.com\r\n" |
| 14290 | "Connection: keep-alive\r\n\r\n"); |
| 14291 | const MockWrite kGetAuth( |
| 14292 | "GET / HTTP/1.1\r\n" |
| 14293 | "Host: www.example.com\r\n" |
| 14294 | "Connection: keep-alive\r\n" |
| 14295 | "Authorization: auth_token\r\n\r\n"); |
| 14296 | |
| 14297 | const MockRead kServerChallenge( |
| 14298 | "HTTP/1.1 401 Unauthorized\r\n" |
| 14299 | "WWW-Authenticate: Mock realm=server\r\n" |
| 14300 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14301 | "Content-Length: 14\r\n\r\n" |
| 14302 | "Unauthorized\r\n"); |
| 14303 | const MockRead kSuccess( |
| 14304 | "HTTP/1.1 200 OK\r\n" |
| 14305 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14306 | "Content-Length: 3\r\n\r\n" |
| 14307 | "Yes"); |
| 14308 | |
| 14309 | MockWrite writes[] = { |
| 14310 | // First round |
| 14311 | kGet, |
| 14312 | // Second round |
| 14313 | kGetAuth, |
| 14314 | // Third round |
| 14315 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14316 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14317 | kGetAuth, |
| 14318 | // Competing request |
| 14319 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14320 | }; |
| 14321 | MockRead reads[] = { |
| 14322 | // First round |
| 14323 | kServerChallenge, |
| 14324 | // Second round |
| 14325 | kServerChallenge, |
| 14326 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14327 | kServerChallenge, |
| 14328 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14329 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14330 | // Competing response |
| 14331 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14332 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14333 | StaticSocketDataProvider data_provider(reads, writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14334 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14335 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 14336 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14337 | |
| 14338 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14339 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14340 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14341 | if (rv == ERR_IO_PENDING) |
| 14342 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14343 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14344 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14345 | ASSERT_TRUE(response); |
| 14346 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14347 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14348 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14349 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14350 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14351 | // In between rounds, another request comes in for the same domain. |
| 14352 | // It should not be able to grab the TCP socket that trans has already |
| 14353 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14354 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14355 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14356 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 14357 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14358 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14359 | // callback_compete.WaitForResult at this point would stall forever, |
| 14360 | // since the HttpNetworkTransaction does not release the request back to |
| 14361 | // the pool until after authentication completes. |
| 14362 | |
| 14363 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14364 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14365 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14366 | if (rv == ERR_IO_PENDING) |
| 14367 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14368 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14369 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14370 | ASSERT_TRUE(response); |
| 14371 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14372 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14373 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14374 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14375 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14376 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14377 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14378 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14379 | if (rv == ERR_IO_PENDING) |
| 14380 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14381 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14382 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14383 | ASSERT_TRUE(response); |
| 14384 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14385 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14386 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14387 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14388 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14389 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14390 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14391 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14392 | if (rv == ERR_IO_PENDING) |
| 14393 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14394 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14395 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14396 | ASSERT_TRUE(response); |
| 14397 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14398 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14399 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14400 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 14401 | // auth handler should transition to a DONE state in concert with the remote |
| 14402 | // server. But that's not something we can test here with a mock handler. |
| 14403 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 14404 | auth_handler->state()); |
| 14405 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14406 | // Read the body since the fourth round was successful. This will also |
| 14407 | // release the socket back to the pool. |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 14408 | scoped_refptr<IOBufferWithSize> io_buf = |
| 14409 | base::MakeRefCounted<IOBufferWithSize>(50); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14410 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14411 | if (rv == ERR_IO_PENDING) |
| 14412 | rv = callback.WaitForResult(); |
| 14413 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14414 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14415 | EXPECT_EQ(0, rv); |
| 14416 | // There are still 0 idle sockets, since the trans_compete transaction |
| 14417 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14418 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14419 | |
| 14420 | // The competing request can now finish. Wait for the headers and then |
| 14421 | // read the body. |
| 14422 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14423 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14424 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14425 | if (rv == ERR_IO_PENDING) |
| 14426 | rv = callback.WaitForResult(); |
| 14427 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14428 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14429 | EXPECT_EQ(0, rv); |
| 14430 | |
| 14431 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14432 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14433 | } |
| 14434 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14435 | // This tests the case that a request is issued via http instead of spdy after |
| 14436 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14437 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14438 | HttpRequestInfo request; |
| 14439 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14440 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14441 | request.traffic_annotation = |
| 14442 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14443 | |
| 14444 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14445 | MockWrite( |
| 14446 | "GET / HTTP/1.1\r\n" |
| 14447 | "Host: www.example.org\r\n" |
| 14448 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14449 | }; |
| 14450 | |
| 14451 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14452 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 14453 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14454 | MockRead("\r\n"), |
| 14455 | MockRead("hello world"), |
| 14456 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14457 | }; |
| 14458 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14459 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14460 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14461 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14462 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14463 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14464 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14465 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14466 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14467 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14468 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14469 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14470 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14471 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14472 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14473 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14474 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14475 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14476 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14477 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14478 | ASSERT_TRUE(response); |
| 14479 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14480 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14481 | |
| 14482 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14483 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14484 | EXPECT_EQ("hello world", response_data); |
| 14485 | |
| 14486 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14487 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14488 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14489 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 14490 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 14491 | // immediate server closing of the socket. |
| 14492 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14493 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14494 | HttpRequestInfo request; |
| 14495 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14496 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14497 | request.traffic_annotation = |
| 14498 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14499 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14500 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14501 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14502 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14503 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14504 | spdy::SpdySerializedFrame req( |
| 14505 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14506 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14507 | |
| 14508 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14509 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14510 | }; |
| 14511 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14512 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14513 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14514 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14515 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14516 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14517 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14518 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14519 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14520 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14521 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14522 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14523 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14524 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14525 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 14526 | // it gets it. This is needed since the auth handler may get destroyed |
| 14527 | // before we get a chance to query it. |
| 14528 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 14529 | public: |
| 14530 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 14531 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 14532 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14533 | |
| 14534 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14535 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 14536 | const HttpRequestInfo* request, |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14537 | CompletionOnceCallback callback, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14538 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14539 | *url_ = request->url; |
| 14540 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14541 | credentials, request, std::move(callback), auth_token); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14542 | } |
| 14543 | |
| 14544 | private: |
| 14545 | GURL* url_; |
| 14546 | }; |
| 14547 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14548 | // Test that if we cancel the transaction as the connection is completing, that |
| 14549 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14550 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14551 | // Setup everything about the connection to complete synchronously, so that |
| 14552 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 14553 | // for is the callback from the HttpStreamRequest. |
| 14554 | // Then cancel the transaction. |
| 14555 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 14556 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14557 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14558 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 14559 | MockRead(SYNCHRONOUS, "hello world"), |
| 14560 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14561 | }; |
| 14562 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14563 | HttpRequestInfo request; |
| 14564 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14565 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14566 | request.traffic_annotation = |
| 14567 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14568 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14569 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14570 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14571 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14572 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14573 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14574 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14575 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14576 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14577 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14578 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14579 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14580 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14581 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14582 | trans.reset(); // Cancel the transaction here. |
| 14583 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14584 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 14585 | } |
| 14586 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14587 | // Test that if a transaction is cancelled after receiving the headers, the |
| 14588 | // stream is drained properly and added back to the socket pool. The main |
| 14589 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 14590 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 14591 | // deleted. |
| 14592 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14593 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14594 | MockRead data_reads[] = { |
| 14595 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 14596 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 14597 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 14598 | MockRead(ASYNC, "1"), |
| 14599 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 14600 | // HttpNetworkTransaction has been deleted. |
| 14601 | MockRead(ASYNC, "2"), |
| 14602 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 14603 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14604 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14605 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14606 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14607 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14608 | |
| 14609 | { |
| 14610 | HttpRequestInfo request; |
| 14611 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14612 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14613 | request.traffic_annotation = |
| 14614 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14615 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14616 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14617 | TestCompletionCallback callback; |
| 14618 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14619 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14620 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14621 | callback.WaitForResult(); |
| 14622 | |
| 14623 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14624 | ASSERT_TRUE(response); |
| 14625 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14626 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14627 | |
| 14628 | // The transaction and HttpRequestInfo are deleted. |
| 14629 | } |
| 14630 | |
| 14631 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14632 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14633 | |
| 14634 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14635 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14636 | } |
| 14637 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14638 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14639 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14640 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14641 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14642 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14643 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14644 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14645 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14646 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14647 | HttpRequestInfo request; |
| 14648 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14649 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14650 | request.traffic_annotation = |
| 14651 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14652 | |
| 14653 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14654 | MockWrite( |
| 14655 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 14656 | "Host: www.example.org\r\n" |
| 14657 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14658 | }; |
| 14659 | |
| 14660 | MockRead data_reads1[] = { |
| 14661 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14662 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14663 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14664 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14665 | }; |
| 14666 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14667 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14668 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14669 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14670 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14671 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14672 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14673 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14674 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14675 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14676 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14677 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14678 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14679 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14680 | |
| 14681 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14682 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14683 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14684 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14685 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14686 | |
| 14687 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14688 | EXPECT_EQ(200, response->headers->response_code()); |
| 14689 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14690 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14691 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14692 | HostPortPair::FromString("myproxy:70")), |
| 14693 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14694 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14695 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14696 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14697 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14698 | |
| 14699 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14700 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14701 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14702 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14703 | } |
| 14704 | |
| 14705 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14706 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14707 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14708 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14709 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14710 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14711 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14712 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14713 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14714 | HttpRequestInfo request; |
| 14715 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14716 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14717 | request.traffic_annotation = |
| 14718 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14719 | |
| 14720 | // Since we have proxy, should try to establish tunnel. |
| 14721 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14722 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14723 | "Host: www.example.org:443\r\n" |
| 14724 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14725 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14726 | MockWrite("GET / HTTP/1.1\r\n" |
| 14727 | "Host: www.example.org\r\n" |
| 14728 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14729 | }; |
| 14730 | |
| 14731 | MockRead data_reads1[] = { |
| 14732 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14733 | |
| 14734 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14735 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14736 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14737 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14738 | }; |
| 14739 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14740 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14741 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14742 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14743 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14744 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14745 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14746 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14747 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14748 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14749 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14750 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14751 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14752 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14753 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14754 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14755 | |
| 14756 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14757 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14758 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14759 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14760 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14761 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14762 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14763 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14764 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14765 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14766 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14767 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14768 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14769 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14770 | |
| 14771 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14772 | EXPECT_EQ(200, response->headers->response_code()); |
| 14773 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14774 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14775 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14776 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14777 | HostPortPair::FromString("myproxy:70")), |
| 14778 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14779 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14780 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14781 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14782 | |
| 14783 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14784 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14785 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14786 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14787 | } |
| 14788 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14789 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 14790 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14791 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14792 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14793 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14794 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14795 | BoundTestNetLog log; |
| 14796 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14797 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14798 | |
| 14799 | HttpRequestInfo request; |
| 14800 | request.method = "GET"; |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14801 | request.url = GURL("https://[::2]:443/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14802 | request.traffic_annotation = |
| 14803 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14804 | |
| 14805 | // Since we have proxy, should try to establish tunnel. |
| 14806 | MockWrite data_writes1[] = { |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14807 | MockWrite("CONNECT [::2]:443 HTTP/1.1\r\n" |
| 14808 | "Host: [::2]:443\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14809 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 14810 | |
| 14811 | MockWrite("GET / HTTP/1.1\r\n" |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14812 | "Host: [::2]\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14813 | "Connection: keep-alive\r\n\r\n"), |
| 14814 | }; |
| 14815 | |
| 14816 | MockRead data_reads1[] = { |
| 14817 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14818 | |
| 14819 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14820 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14821 | MockRead("Content-Length: 100\r\n\r\n"), |
| 14822 | MockRead(SYNCHRONOUS, OK), |
| 14823 | }; |
| 14824 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14825 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14826 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14827 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14828 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14829 | |
| 14830 | TestCompletionCallback callback1; |
| 14831 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14832 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14833 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14834 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14835 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14836 | |
| 14837 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14838 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14839 | TestNetLogEntry::List entries; |
| 14840 | log.GetEntries(&entries); |
| 14841 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14842 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14843 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14844 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14845 | entries, pos, |
| 14846 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14847 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14848 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14849 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14850 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14851 | |
| 14852 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14853 | EXPECT_EQ(200, response->headers->response_code()); |
| 14854 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14855 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14856 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14857 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14858 | HostPortPair::FromString("myproxy:70")), |
| 14859 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14860 | |
| 14861 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14862 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14863 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14864 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14865 | } |
| 14866 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14867 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 14868 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14869 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14870 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 14871 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14872 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14873 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14874 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14875 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14876 | HttpRequestInfo request; |
| 14877 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14878 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14879 | request.traffic_annotation = |
| 14880 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14881 | |
| 14882 | // Since we have proxy, should try to establish tunnel. |
| 14883 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14884 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14885 | "Host: www.example.org:443\r\n" |
| 14886 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14887 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14888 | MockWrite("GET / HTTP/1.1\r\n" |
| 14889 | "Host: www.example.org\r\n" |
| 14890 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14891 | }; |
| 14892 | |
| 14893 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14894 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14895 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14896 | }; |
| 14897 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14898 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14899 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14900 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14901 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14902 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14903 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14904 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14905 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14906 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14907 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14908 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14909 | |
| 14910 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14911 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14912 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14913 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14914 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14915 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14916 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14917 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14918 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14919 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14920 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14921 | } |
| 14922 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14923 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14924 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14925 | spdy::SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14926 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14927 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14928 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14929 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 14930 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14931 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14932 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14933 | }; |
| 14934 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14935 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14936 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14937 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14938 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14939 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14940 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14941 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14942 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14943 | |
| 14944 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14945 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14946 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 14947 | PRIVACY_MODE_DISABLED, |
| 14948 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14949 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 14950 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14951 | |
| 14952 | HttpRequestInfo request; |
| 14953 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14954 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14955 | request.traffic_annotation = |
| 14956 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14957 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14958 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14959 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14960 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14961 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14962 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14963 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14964 | } |
| 14965 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14966 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14967 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14968 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14969 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14970 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14971 | request_info.url = GURL("https://www.example.com/"); |
| 14972 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14973 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14974 | request_info.traffic_annotation = |
| 14975 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14976 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14977 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14978 | MockWrite data_writes[] = { |
| 14979 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14980 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14981 | StaticSocketDataProvider data(base::span<MockRead>(), data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14982 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14983 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14984 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14985 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14986 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14987 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14988 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14989 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14990 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14991 | rv = callback.WaitForResult(); |
| 14992 | ASSERT_EQ(error, rv); |
| 14993 | } |
| 14994 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14995 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14996 | // Just check a grab bag of cert errors. |
| 14997 | static const int kErrors[] = { |
| 14998 | ERR_CERT_COMMON_NAME_INVALID, |
| 14999 | ERR_CERT_AUTHORITY_INVALID, |
| 15000 | ERR_CERT_DATE_INVALID, |
| 15001 | }; |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 15002 | for (size_t i = 0; i < base::size(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 15003 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 15004 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 15005 | } |
| 15006 | } |
| 15007 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15008 | // Ensure that a client certificate is removed from the SSL client auth |
| 15009 | // cache when: |
| 15010 | // 1) No proxy is involved. |
| 15011 | // 2) TLS False Start is disabled. |
| 15012 | // 3) The initial TLS handshake requests a client certificate. |
| 15013 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15014 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15015 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15016 | request_info.url = GURL("https://www.example.com/"); |
| 15017 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15018 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15019 | request_info.traffic_annotation = |
| 15020 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15021 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15022 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15023 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15024 | |
| 15025 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 15026 | // CertificateRequest is received for the first time, the handshake will |
| 15027 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15028 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15029 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15030 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15031 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15032 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15033 | |
| 15034 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 15035 | // False Start is not being used, the result of the SSL handshake will be |
| 15036 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 15037 | // matches the result of a server sending a handshake_failure alert, |
| 15038 | // rather than a Finished message, because it requires a client |
| 15039 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15040 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15041 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15042 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15043 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15044 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15045 | |
| 15046 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 15047 | // connection to a server fails during an SSL handshake, |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15048 | // HttpNetworkTransaction will attempt to fallback to TLSv1.2 if the previous |
| 15049 | // connection was attempted with TLSv1.3. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15050 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15051 | // requiring a client certificate, this fallback handshake should also |
| 15052 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15053 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15054 | ssl_data3.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15055 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15056 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15057 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15058 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15059 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15060 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 15061 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 15062 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 15063 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15064 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15065 | // requiring a client certificate, this fallback handshake should also |
| 15066 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15067 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15068 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15069 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15070 | StaticSocketDataProvider data4; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15071 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15072 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15073 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15074 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15075 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15076 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15077 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15078 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15079 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15080 | |
| 15081 | // Complete the SSL handshake, which should abort due to requiring a |
| 15082 | // client certificate. |
| 15083 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15084 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15085 | |
| 15086 | // Indicate that no certificate should be supplied. From the perspective |
| 15087 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15088 | // certificate, so this is the same as supply a |
| 15089 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15090 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15091 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15092 | |
| 15093 | // Ensure the certificate was added to the client auth cache before |
| 15094 | // allowing the connection to continue restarting. |
| 15095 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15096 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15097 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15098 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15099 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15100 | |
| 15101 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15102 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15103 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15104 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15105 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15106 | |
| 15107 | // Ensure that the client certificate is removed from the cache on a |
| 15108 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15109 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15110 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15111 | } |
| 15112 | |
| 15113 | // Ensure that a client certificate is removed from the SSL client auth |
| 15114 | // cache when: |
| 15115 | // 1) No proxy is involved. |
| 15116 | // 2) TLS False Start is enabled. |
| 15117 | // 3) The initial TLS handshake requests a client certificate. |
| 15118 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15119 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15120 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15121 | request_info.url = GURL("https://www.example.com/"); |
| 15122 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15123 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15124 | request_info.traffic_annotation = |
| 15125 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15126 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15127 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15128 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15129 | |
| 15130 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 15131 | // return successfully after reading up to the peer's Certificate message. |
| 15132 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 15133 | // enqueue application data to be sent in the same packet as the |
| 15134 | // ChangeCipherSpec and Finished messages. |
| 15135 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 15136 | // called, which expects to process the peer's ChangeCipherSpec and |
| 15137 | // Finished messages. If there was an error negotiating with the peer, |
| 15138 | // such as due to the peer requiring a client certificate when none was |
| 15139 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 15140 | // called. |
| 15141 | |
| 15142 | // Like the non-False Start case, when a client certificate is requested by |
| 15143 | // the peer, the handshake is aborted during the Connect() call. |
| 15144 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15145 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15146 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15147 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15148 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15149 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15150 | |
| 15151 | // When a client certificate is supplied, Connect() will not be aborted |
| 15152 | // when the peer requests the certificate. Instead, the handshake will |
| 15153 | // artificially succeed, allowing the caller to write the HTTP request to |
| 15154 | // the socket. The handshake messages are not processed until Read() is |
| 15155 | // called, which then detects that the handshake was aborted, due to the |
| 15156 | // peer sending a handshake_failure because it requires a client |
| 15157 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15158 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15159 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15160 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15161 | MockRead data2_reads[] = { |
| 15162 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15163 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15164 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15165 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15166 | |
| 15167 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15168 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 15169 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15170 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15171 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15172 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15173 | StaticSocketDataProvider data3(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15174 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15175 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15176 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 15177 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15178 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15179 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15180 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15181 | StaticSocketDataProvider data4(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15182 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15183 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15184 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15185 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15186 | ssl_data5.cert_request_info = cert_request.get(); |
| 15187 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15188 | StaticSocketDataProvider data5(data2_reads, base::span<MockWrite>()); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15189 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 15190 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15191 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15192 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15193 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15194 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15195 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15196 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15197 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15198 | |
| 15199 | // Complete the SSL handshake, which should abort due to requiring a |
| 15200 | // client certificate. |
| 15201 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15202 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15203 | |
| 15204 | // Indicate that no certificate should be supplied. From the perspective |
| 15205 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15206 | // certificate, so this is the same as supply a |
| 15207 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15208 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15209 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15210 | |
| 15211 | // Ensure the certificate was added to the client auth cache before |
| 15212 | // allowing the connection to continue restarting. |
| 15213 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15214 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15215 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15216 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15217 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15218 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15219 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15220 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15221 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15222 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15223 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15224 | |
| 15225 | // Ensure that the client certificate is removed from the cache on a |
| 15226 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15227 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15228 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15229 | } |
| 15230 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15231 | // Ensure that a client certificate is removed from the SSL client auth |
| 15232 | // cache when: |
| 15233 | // 1) An HTTPS proxy is involved. |
| 15234 | // 3) The HTTPS proxy requests a client certificate. |
| 15235 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 15236 | // proxy. |
| 15237 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 15238 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15239 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15240 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 15241 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15242 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15243 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15244 | |
| 15245 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15246 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15247 | |
| 15248 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 15249 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 15250 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 15251 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15252 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15253 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15254 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15255 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15256 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15257 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15258 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15259 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15260 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15261 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15262 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15263 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15264 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 15265 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15266 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15267 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15268 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15269 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15270 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15271 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15272 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15273 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15274 | requests[0].url = GURL("https://www.example.com/"); |
| 15275 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15276 | requests[0].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15277 | requests[0].traffic_annotation = |
| 15278 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15279 | |
| 15280 | requests[1].url = GURL("http://www.example.com/"); |
| 15281 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15282 | requests[1].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15283 | requests[1].traffic_annotation = |
| 15284 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15285 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 15286 | for (size_t i = 0; i < base::size(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15287 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15288 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15289 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15290 | |
| 15291 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15292 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15293 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15294 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15295 | |
| 15296 | // Complete the SSL handshake, which should abort due to requiring a |
| 15297 | // client certificate. |
| 15298 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15299 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15300 | |
| 15301 | // Indicate that no certificate should be supplied. From the perspective |
| 15302 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15303 | // certificate, so this is the same as supply a |
| 15304 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15305 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15306 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15307 | |
| 15308 | // Ensure the certificate was added to the client auth cache before |
| 15309 | // allowing the connection to continue restarting. |
| 15310 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15311 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15312 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15313 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15314 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15315 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 15316 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15317 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15318 | HostPortPair("www.example.com", 443), &client_cert, |
| 15319 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15320 | |
| 15321 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 15322 | // then consume ssl_data3, which should also fail. The result code is |
| 15323 | // checked against what ssl_data3 should return. |
| 15324 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15325 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15326 | |
| 15327 | // Now that the new handshake has failed, ensure that the client |
| 15328 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15329 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15330 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15331 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15332 | HostPortPair("www.example.com", 443), &client_cert, |
| 15333 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15334 | } |
| 15335 | } |
| 15336 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15337 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15338 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15339 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15340 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15341 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15342 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15343 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15344 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15345 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15346 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15347 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15348 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15349 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15350 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15351 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15352 | spdy::SpdySerializedFrame host1_resp( |
| 15353 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15354 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15355 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15356 | spdy::SpdySerializedFrame host2_resp( |
| 15357 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 15358 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15359 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15360 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15361 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15362 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15363 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15364 | }; |
| 15365 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15366 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15367 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15368 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15369 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15370 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15371 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15372 | HttpRequestInfo request1; |
| 15373 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15374 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15375 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15376 | request1.traffic_annotation = |
| 15377 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15378 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15379 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15380 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15381 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15382 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15383 | |
| 15384 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15385 | ASSERT_TRUE(response); |
| 15386 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15387 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15388 | |
| 15389 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15390 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15391 | EXPECT_EQ("hello!", response_data); |
| 15392 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15393 | // Preload mail.example.com into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15394 | rv = session_deps_.host_resolver->LoadIntoCache( |
| 15395 | HostPortPair("mail.example.com", 443), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15396 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15397 | |
| 15398 | HttpRequestInfo request2; |
| 15399 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15400 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15401 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15402 | request2.traffic_annotation = |
| 15403 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15404 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15405 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15406 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15407 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15408 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15409 | |
| 15410 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15411 | ASSERT_TRUE(response); |
| 15412 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15413 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15414 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15415 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15416 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15417 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15418 | } |
| 15419 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15420 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15421 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15422 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15423 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15424 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15425 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15426 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15427 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15428 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15429 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15430 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15431 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15432 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15433 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15434 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15435 | spdy::SpdySerializedFrame host1_resp( |
| 15436 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15437 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15438 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15439 | spdy::SpdySerializedFrame host2_resp( |
| 15440 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 15441 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15442 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15443 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15444 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15445 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15446 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15447 | }; |
| 15448 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15449 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15450 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15451 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15452 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15453 | |
| 15454 | TestCompletionCallback callback; |
| 15455 | HttpRequestInfo request1; |
| 15456 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15457 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15458 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15459 | request1.traffic_annotation = |
| 15460 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15461 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15462 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15463 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15464 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15465 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15466 | |
| 15467 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15468 | ASSERT_TRUE(response); |
| 15469 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15470 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15471 | |
| 15472 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15473 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15474 | EXPECT_EQ("hello!", response_data); |
| 15475 | |
| 15476 | HttpRequestInfo request2; |
| 15477 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15478 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15479 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15480 | request2.traffic_annotation = |
| 15481 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15482 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15483 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15484 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15485 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15486 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15487 | |
| 15488 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15489 | ASSERT_TRUE(response); |
| 15490 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15491 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15492 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15493 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15494 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15495 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15496 | } |
| 15497 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15498 | // Regression test for https://crbug.com/546991. |
| 15499 | // The server might not be able to serve an IP pooled request, and might send a |
| 15500 | // 421 Misdirected Request response status to indicate this. |
| 15501 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 15502 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 15503 | // Two hosts resolve to the same IP address. |
| 15504 | const std::string ip_addr = "1.2.3.4"; |
| 15505 | IPAddress ip; |
| 15506 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 15507 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15508 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15509 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15510 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 15511 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 15512 | |
| 15513 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15514 | |
| 15515 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15516 | spdy::SpdySerializedFrame req1( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15517 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 15518 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15519 | spdy::SpdySerializedFrame req2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15520 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15521 | spdy::SpdySerializedFrame rst( |
| 15522 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15523 | MockWrite writes1[] = { |
| 15524 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 15525 | CreateMockWrite(rst, 6), |
| 15526 | }; |
| 15527 | |
| 15528 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15529 | spdy::SpdySerializedFrame resp1( |
| 15530 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15531 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15532 | spdy::SpdyHeaderBlock response_headers; |
| 15533 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 15534 | spdy::SpdySerializedFrame resp2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15535 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 15536 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15537 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15538 | |
| 15539 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15540 | SequencedSocketData data1(connect1, reads1, writes1); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15541 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15542 | |
| 15543 | AddSSLSocketData(); |
| 15544 | |
| 15545 | // Retry the second request on a second connection. |
| 15546 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15547 | spdy::SpdySerializedFrame req3( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15548 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15549 | MockWrite writes2[] = { |
| 15550 | CreateMockWrite(req3, 0), |
| 15551 | }; |
| 15552 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15553 | spdy::SpdySerializedFrame resp3( |
| 15554 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15555 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15556 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15557 | MockRead(ASYNC, 0, 3)}; |
| 15558 | |
| 15559 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15560 | SequencedSocketData data2(connect2, reads2, writes2); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15561 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15562 | |
| 15563 | AddSSLSocketData(); |
| 15564 | |
| 15565 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15566 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 15567 | HostPortPair("mail.example.com", 443), base::nullopt); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15568 | EXPECT_THAT(rv, IsOk()); |
| 15569 | |
| 15570 | HttpRequestInfo request1; |
| 15571 | request1.method = "GET"; |
| 15572 | request1.url = GURL("https://www.example.org/"); |
| 15573 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15574 | request1.traffic_annotation = |
| 15575 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15576 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15577 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15578 | TestCompletionCallback callback; |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15579 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15580 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15581 | rv = callback.WaitForResult(); |
| 15582 | EXPECT_THAT(rv, IsOk()); |
| 15583 | |
| 15584 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15585 | ASSERT_TRUE(response); |
| 15586 | ASSERT_TRUE(response->headers); |
| 15587 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15588 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15589 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15590 | std::string response_data; |
| 15591 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15592 | EXPECT_EQ("hello!", response_data); |
| 15593 | |
| 15594 | HttpRequestInfo request2; |
| 15595 | request2.method = "GET"; |
| 15596 | request2.url = GURL("https://mail.example.org/"); |
| 15597 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15598 | request2.traffic_annotation = |
| 15599 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15600 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15601 | |
| 15602 | BoundTestNetLog log; |
| 15603 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15604 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15605 | rv = callback.WaitForResult(); |
| 15606 | EXPECT_THAT(rv, IsOk()); |
| 15607 | |
| 15608 | response = trans2.GetResponseInfo(); |
| 15609 | ASSERT_TRUE(response); |
| 15610 | ASSERT_TRUE(response->headers); |
| 15611 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15612 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15613 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15614 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15615 | EXPECT_EQ("hello!", response_data); |
| 15616 | |
| 15617 | TestNetLogEntry::List entries; |
| 15618 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15619 | ExpectLogContainsSomewhere( |
| 15620 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15621 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15622 | } |
| 15623 | |
| 15624 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 15625 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 15626 | // portions of the response. |
| 15627 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 15628 | // Two hosts resolve to the same IP address. |
| 15629 | const std::string ip_addr = "1.2.3.4"; |
| 15630 | IPAddress ip; |
| 15631 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 15632 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15633 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15634 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15635 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 15636 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 15637 | |
| 15638 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15639 | |
| 15640 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15641 | spdy::SpdySerializedFrame req1( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15642 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 15643 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15644 | spdy::SpdySerializedFrame req2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15645 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15646 | spdy::SpdySerializedFrame rst( |
| 15647 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15648 | MockWrite writes1[] = { |
| 15649 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 15650 | CreateMockWrite(rst, 6), |
| 15651 | }; |
| 15652 | |
| 15653 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15654 | spdy::SpdySerializedFrame resp1( |
| 15655 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15656 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15657 | spdy::SpdyHeaderBlock response_headers; |
| 15658 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 15659 | spdy::SpdySerializedFrame resp2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15660 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 15661 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15662 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15663 | |
| 15664 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15665 | SequencedSocketData data1(connect1, reads1, writes1); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15666 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15667 | |
| 15668 | AddSSLSocketData(); |
| 15669 | |
| 15670 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 15671 | // Retry again. |
| 15672 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15673 | spdy::SpdySerializedFrame req3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15674 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15675 | MockWrite writes2[] = { |
| 15676 | CreateMockWrite(req3, 0), |
| 15677 | }; |
| 15678 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15679 | spdy::SpdySerializedFrame resp3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15680 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15681 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15682 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15683 | MockRead(ASYNC, 0, 3)}; |
| 15684 | |
| 15685 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15686 | SequencedSocketData data2(connect2, reads2, writes2); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15687 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15688 | |
| 15689 | AddSSLSocketData(); |
| 15690 | |
| 15691 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15692 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 15693 | HostPortPair("mail.example.com", 443), base::nullopt); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15694 | EXPECT_THAT(rv, IsOk()); |
| 15695 | |
| 15696 | HttpRequestInfo request1; |
| 15697 | request1.method = "GET"; |
| 15698 | request1.url = GURL("https://www.example.org/"); |
| 15699 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15700 | request1.traffic_annotation = |
| 15701 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15702 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15703 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15704 | TestCompletionCallback callback; |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15705 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15706 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15707 | rv = callback.WaitForResult(); |
| 15708 | EXPECT_THAT(rv, IsOk()); |
| 15709 | |
| 15710 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15711 | ASSERT_TRUE(response); |
| 15712 | ASSERT_TRUE(response->headers); |
| 15713 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15714 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15715 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15716 | std::string response_data; |
| 15717 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15718 | EXPECT_EQ("hello!", response_data); |
| 15719 | |
| 15720 | HttpRequestInfo request2; |
| 15721 | request2.method = "GET"; |
| 15722 | request2.url = GURL("https://mail.example.org/"); |
| 15723 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15724 | request2.traffic_annotation = |
| 15725 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15726 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15727 | |
| 15728 | BoundTestNetLog log; |
| 15729 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15730 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15731 | rv = callback.WaitForResult(); |
| 15732 | EXPECT_THAT(rv, IsOk()); |
| 15733 | |
| 15734 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 15735 | // caller. |
| 15736 | response = trans2.GetResponseInfo(); |
| 15737 | ASSERT_TRUE(response); |
| 15738 | ASSERT_TRUE(response->headers); |
| 15739 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 15740 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15741 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15742 | EXPECT_TRUE(response->ssl_info.cert); |
| 15743 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15744 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15745 | } |
| 15746 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15747 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 15748 | UseIPConnectionPoolingWithHostCacheExpiration) { |
Eric Orth | 1da75de | 2019-02-20 21:10:34 | [diff] [blame] | 15749 | // Set up HostResolver to invalidate cached entries after 1 cached resolve. |
| 15750 | session_deps_.host_resolver = |
| 15751 | std::make_unique<MockCachingHostResolver>(1 /* cache_invalidation_num */); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15752 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15753 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15754 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15755 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15756 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15757 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15758 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15759 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15760 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15761 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15762 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15763 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15764 | spdy::SpdySerializedFrame host1_resp( |
| 15765 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15766 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15767 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15768 | spdy::SpdySerializedFrame host2_resp( |
| 15769 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 15770 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15771 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15772 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15773 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15774 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15775 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15776 | }; |
| 15777 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15778 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15779 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15780 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15781 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15782 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15783 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15784 | HttpRequestInfo request1; |
| 15785 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15786 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15787 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15788 | request1.traffic_annotation = |
| 15789 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15790 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15791 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15792 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15793 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15794 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15795 | |
| 15796 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15797 | ASSERT_TRUE(response); |
| 15798 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15799 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15800 | |
| 15801 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15802 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15803 | EXPECT_EQ("hello!", response_data); |
| 15804 | |
| 15805 | // Preload cache entries into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 15806 | rv = session_deps_.host_resolver->LoadIntoCache( |
| 15807 | HostPortPair("mail.example.com", 443), base::nullopt); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15808 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15809 | |
| 15810 | HttpRequestInfo request2; |
| 15811 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15812 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15813 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15814 | request2.traffic_annotation = |
| 15815 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15816 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15817 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15818 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15819 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15820 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15821 | |
| 15822 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15823 | ASSERT_TRUE(response); |
| 15824 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15825 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15826 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15827 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15828 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15829 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15830 | } |
| 15831 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15832 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15833 | const std::string https_url = "https://www.example.org:8080/"; |
| 15834 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15835 | |
| 15836 | // SPDY GET for HTTPS URL |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15837 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15838 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15839 | |
| 15840 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15841 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15842 | }; |
| 15843 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15844 | spdy::SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15845 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15846 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15847 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15848 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15849 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15850 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15851 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15852 | |
| 15853 | // HTTP GET for the HTTP URL |
| 15854 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15855 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15856 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15857 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15858 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15859 | }; |
| 15860 | |
| 15861 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15862 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 15863 | MockRead(ASYNC, 2, "hello"), |
| 15864 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15865 | }; |
| 15866 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15867 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15868 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15869 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15870 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15871 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15872 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15873 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15874 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15875 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15876 | |
| 15877 | // Start the first transaction to set up the SpdySession |
| 15878 | HttpRequestInfo request1; |
| 15879 | request1.method = "GET"; |
| 15880 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15881 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15882 | request1.traffic_annotation = |
| 15883 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15884 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15885 | TestCompletionCallback callback1; |
| 15886 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15887 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15888 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15889 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15890 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15891 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15892 | |
| 15893 | // Now, start the HTTP request |
| 15894 | HttpRequestInfo request2; |
| 15895 | request2.method = "GET"; |
| 15896 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15897 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15898 | request2.traffic_annotation = |
| 15899 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15900 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15901 | TestCompletionCallback callback2; |
| 15902 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15903 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15904 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15905 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15906 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15907 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15908 | } |
| 15909 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15910 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 15911 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15912 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15913 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 15914 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15915 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15916 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15917 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15918 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15919 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15920 | |
| 15921 | // No data should be read from the alternative, because HTTP/1.1 is |
| 15922 | // negotiated. |
| 15923 | StaticSocketDataProvider data; |
| 15924 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15925 | |
| 15926 | // 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] | 15927 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15928 | // mocked. This way the request relies on the alternate Job. |
| 15929 | StaticSocketDataProvider data_refused; |
| 15930 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 15931 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 15932 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15933 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15934 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15935 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15936 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15937 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15938 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15939 | http_server_properties->SetHttp2AlternativeService( |
| 15940 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15941 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15942 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15943 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15944 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15945 | request.url = GURL("https://www.example.org:443"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15946 | request.traffic_annotation = |
| 15947 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15948 | TestCompletionCallback callback; |
| 15949 | |
| 15950 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15951 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15952 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15953 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15954 | } |
| 15955 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15956 | // 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] | 15957 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15958 | // succeeds, the request should succeed, even if the latter fails because |
| 15959 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15960 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15961 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 15962 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15963 | |
| 15964 | // Negotiate HTTP/1.1 with alternative. |
| 15965 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15966 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15967 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 15968 | |
| 15969 | // No data should be read from the alternative, because HTTP/1.1 is |
| 15970 | // negotiated. |
| 15971 | StaticSocketDataProvider data; |
| 15972 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15973 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15974 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15975 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15976 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15977 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 15978 | |
| 15979 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15980 | MockWrite("GET / HTTP/1.1\r\n" |
| 15981 | "Host: www.example.org\r\n" |
| 15982 | "Connection: keep-alive\r\n\r\n"), |
| 15983 | MockWrite("GET /second HTTP/1.1\r\n" |
| 15984 | "Host: www.example.org\r\n" |
| 15985 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15986 | }; |
| 15987 | |
| 15988 | MockRead http_reads[] = { |
| 15989 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15990 | MockRead("Content-Type: text/html\r\n"), |
| 15991 | MockRead("Content-Length: 6\r\n\r\n"), |
| 15992 | MockRead("foobar"), |
| 15993 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15994 | MockRead("Content-Type: text/html\r\n"), |
| 15995 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15996 | MockRead("another"), |
| 15997 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15998 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15999 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16000 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16001 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16002 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16003 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16004 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16005 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16006 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16007 | http_server_properties->SetHttp2AlternativeService( |
| 16008 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16009 | |
| 16010 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 16011 | HttpRequestInfo request1; |
| 16012 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16013 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16014 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16015 | request1.traffic_annotation = |
| 16016 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16017 | TestCompletionCallback callback1; |
| 16018 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16019 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16020 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16021 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16022 | |
| 16023 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16024 | ASSERT_TRUE(response1); |
| 16025 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16026 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 16027 | |
| 16028 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16029 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16030 | EXPECT_EQ("foobar", response_data1); |
| 16031 | |
| 16032 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 16033 | // for alternative service. |
| 16034 | EXPECT_TRUE( |
| 16035 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 16036 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16037 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16038 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16039 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16040 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 16041 | HttpRequestInfo request2; |
| 16042 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16043 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16044 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16045 | request2.traffic_annotation = |
| 16046 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16047 | TestCompletionCallback callback2; |
| 16048 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16049 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16050 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16051 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16052 | |
| 16053 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16054 | ASSERT_TRUE(response2); |
| 16055 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16056 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 16057 | |
| 16058 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16059 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16060 | EXPECT_EQ("another", response_data2); |
| 16061 | } |
| 16062 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16063 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 16064 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 16065 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16066 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16067 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16068 | HostPortPair alternative("alternative.example.org", 443); |
| 16069 | std::string origin_url = "https://origin.example.org:443"; |
| 16070 | std::string alternative_url = "https://alternative.example.org:443"; |
| 16071 | |
| 16072 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 16073 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16074 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16075 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16076 | |
| 16077 | // HTTP/1.1 data for |request1| and |request2|. |
| 16078 | MockWrite http_writes[] = { |
| 16079 | MockWrite( |
| 16080 | "GET / HTTP/1.1\r\n" |
| 16081 | "Host: alternative.example.org\r\n" |
| 16082 | "Connection: keep-alive\r\n\r\n"), |
| 16083 | MockWrite( |
| 16084 | "GET / HTTP/1.1\r\n" |
| 16085 | "Host: alternative.example.org\r\n" |
| 16086 | "Connection: keep-alive\r\n\r\n"), |
| 16087 | }; |
| 16088 | |
| 16089 | MockRead http_reads[] = { |
| 16090 | MockRead( |
| 16091 | "HTTP/1.1 200 OK\r\n" |
| 16092 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16093 | "Content-Length: 40\r\n\r\n" |
| 16094 | "first HTTP/1.1 response from alternative"), |
| 16095 | MockRead( |
| 16096 | "HTTP/1.1 200 OK\r\n" |
| 16097 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16098 | "Content-Length: 41\r\n\r\n" |
| 16099 | "second HTTP/1.1 response from alternative"), |
| 16100 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16101 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16102 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16103 | |
| 16104 | // This test documents that an alternate Job should not pool to an already |
| 16105 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16106 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16107 | StaticSocketDataProvider data_refused; |
| 16108 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 16109 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 16110 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16111 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16112 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16113 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16114 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16115 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16116 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16117 | http_server_properties->SetHttp2AlternativeService( |
| 16118 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16119 | |
| 16120 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16121 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16122 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16123 | request1.method = "GET"; |
| 16124 | request1.url = GURL(alternative_url); |
| 16125 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16126 | request1.traffic_annotation = |
| 16127 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16128 | TestCompletionCallback callback1; |
| 16129 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16130 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16131 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16132 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16133 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16134 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16135 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16136 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16137 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 16138 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16139 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16140 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 16141 | |
| 16142 | // Request for origin.example.org, which has an alternative service. This |
| 16143 | // will start two Jobs: the alternative looks for connections to pool to, |
| 16144 | // 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] | 16145 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16146 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16147 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16148 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16149 | request2.method = "GET"; |
| 16150 | request2.url = GURL(origin_url); |
| 16151 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16152 | request2.traffic_annotation = |
| 16153 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16154 | TestCompletionCallback callback2; |
| 16155 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16156 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16157 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16158 | |
| 16159 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 16160 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16161 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16162 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16163 | request3.method = "GET"; |
| 16164 | request3.url = GURL(alternative_url); |
| 16165 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16166 | request3.traffic_annotation = |
| 16167 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16168 | TestCompletionCallback callback3; |
| 16169 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16170 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16171 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16172 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16173 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16174 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16175 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16176 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16177 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 16178 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16179 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16180 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 16181 | } |
| 16182 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16183 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16184 | const std::string https_url = "https://www.example.org:8080/"; |
| 16185 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16186 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16187 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16188 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16189 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16190 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16191 | const HostPortPair host_port_pair("www.example.org", 8080); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16192 | spdy::SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 16193 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16194 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16195 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16196 | spdy::SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 16197 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 16198 | |
| 16199 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16200 | spdy::SpdyHeaderBlock req2_block; |
| 16201 | req2_block[spdy::kHttp2MethodHeader] = "GET"; |
| 16202 | req2_block[spdy::kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 16203 | req2_block[spdy::kHttp2SchemeHeader] = "http"; |
| 16204 | req2_block[spdy::kHttp2PathHeader] = "/"; |
| 16205 | spdy::SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16206 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16207 | |
| 16208 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16209 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 16210 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16211 | }; |
| 16212 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16213 | spdy::SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16214 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16215 | spdy::SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16216 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16217 | spdy::SpdySerializedFrame body1( |
| 16218 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 16219 | spdy::SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16220 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16221 | spdy::SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16222 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16223 | spdy::SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 16224 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16225 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16226 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16227 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16228 | CreateMockRead(wrapped_resp1, 4), |
| 16229 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16230 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16231 | CreateMockRead(resp2, 8), |
| 16232 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16233 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 16234 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16235 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16236 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16237 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 16238 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16239 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16240 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16241 | ProxyResolutionService::CreateFixedFromPacResult( |
| 16242 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 16243 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16244 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16245 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16246 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16247 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16248 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16249 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16250 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16251 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16252 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16253 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16254 | |
| 16255 | // Start the first transaction to set up the SpdySession |
| 16256 | HttpRequestInfo request1; |
| 16257 | request1.method = "GET"; |
| 16258 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16259 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16260 | request1.traffic_annotation = |
| 16261 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16262 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16263 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16264 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16265 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16266 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16267 | data1.RunUntilPaused(); |
| 16268 | base::RunLoop().RunUntilIdle(); |
| 16269 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16270 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16271 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16272 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16273 | LoadTimingInfo load_timing_info1; |
| 16274 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 16275 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 16276 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 16277 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16278 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16279 | HttpRequestInfo request2; |
| 16280 | request2.method = "GET"; |
| 16281 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16282 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16283 | request2.traffic_annotation = |
| 16284 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16285 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16286 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16287 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16288 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16289 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16290 | data1.RunUntilPaused(); |
| 16291 | base::RunLoop().RunUntilIdle(); |
| 16292 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16293 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16294 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16295 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16296 | |
| 16297 | LoadTimingInfo load_timing_info2; |
| 16298 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 16299 | // The established SPDY sessions is considered reused by the HTTP request. |
| 16300 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 16301 | // HTTP requests over a SPDY session should have a different connection |
| 16302 | // socket_log_id than requests over a tunnel. |
| 16303 | 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] | 16304 | } |
| 16305 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16306 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 16307 | // that we do not pool other origins that resolve to the same IP when |
| 16308 | // the certificate does not match the new origin. |
| 16309 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16310 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16311 | const std::string url1 = "http://www.example.org/"; |
| 16312 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16313 | const std::string ip_addr = "1.2.3.4"; |
| 16314 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16315 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16316 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16317 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16318 | // SPDY GET for HTTP URL (through SPDY proxy) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16319 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16320 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16321 | spdy::SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16322 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16323 | |
| 16324 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16325 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16326 | }; |
| 16327 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16328 | spdy::SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 16329 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16330 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16331 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 16332 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16333 | }; |
| 16334 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16335 | SequencedSocketData data1(reads1, writes1); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 16336 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 16337 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16338 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 16339 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16340 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16341 | |
| 16342 | // SPDY GET for HTTPS URL (direct) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16343 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16344 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16345 | |
| 16346 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16347 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16348 | }; |
| 16349 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16350 | spdy::SpdySerializedFrame resp2( |
| 16351 | spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
| 16352 | spdy::SpdySerializedFrame body2( |
| 16353 | spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16354 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16355 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16356 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16357 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16358 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16359 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16360 | |
| 16361 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 16362 | // all others direct. |
| 16363 | ProxyConfig proxy_config; |
| 16364 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16365 | session_deps_.proxy_resolution_service = |
| 16366 | std::make_unique<ProxyResolutionService>( |
| 16367 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 16368 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 16369 | nullptr, nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16370 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16371 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16372 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16373 | // Load a valid cert. Note, that this does not need to |
| 16374 | // be valid for proxy because the MockSSLClientSocket does |
| 16375 | // not actually verify it. But SpdySession will use this |
| 16376 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 16377 | ssl1.ssl_info.cert = |
| 16378 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 16379 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16380 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16381 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16382 | |
| 16383 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16384 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16385 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16386 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16387 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16388 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16389 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16390 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16391 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16392 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16393 | |
| 16394 | // Start the first transaction to set up the SpdySession |
| 16395 | HttpRequestInfo request1; |
| 16396 | request1.method = "GET"; |
| 16397 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16398 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16399 | request1.traffic_annotation = |
| 16400 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16401 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16402 | TestCompletionCallback callback1; |
| 16403 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16404 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16405 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16406 | data1.RunUntilPaused(); |
| 16407 | base::RunLoop().RunUntilIdle(); |
| 16408 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16409 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16410 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16411 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16412 | |
| 16413 | // Now, start the HTTP request |
| 16414 | HttpRequestInfo request2; |
| 16415 | request2.method = "GET"; |
| 16416 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16417 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16418 | request2.traffic_annotation = |
| 16419 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16420 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16421 | TestCompletionCallback callback2; |
| 16422 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16423 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16424 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16425 | |
| 16426 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16427 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16428 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16429 | } |
| 16430 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16431 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 16432 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 16433 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 16434 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16435 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16436 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16437 | |
| 16438 | MockRead reads1[] = { |
| 16439 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 16440 | }; |
| 16441 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16442 | SequencedSocketData data1(reads1, base::span<MockWrite>()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16443 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16444 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16445 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16446 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16447 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16448 | }; |
| 16449 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16450 | spdy::SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 16451 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16452 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16453 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 16454 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16455 | }; |
| 16456 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16457 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16458 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16459 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16460 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16461 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16462 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16463 | |
| 16464 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16465 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16466 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16467 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16468 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16469 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16470 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16471 | |
| 16472 | // Start the first transaction to set up the SpdySession and verify that |
| 16473 | // connection was closed. |
| 16474 | HttpRequestInfo request1; |
| 16475 | request1.method = "GET"; |
| 16476 | request1.url = GURL(https_url); |
| 16477 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16478 | request1.traffic_annotation = |
| 16479 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16480 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16481 | TestCompletionCallback callback1; |
| 16482 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16483 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16484 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16485 | |
| 16486 | // Now, start the second request and make sure it succeeds. |
| 16487 | HttpRequestInfo request2; |
| 16488 | request2.method = "GET"; |
| 16489 | request2.url = GURL(https_url); |
| 16490 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16491 | request2.traffic_annotation = |
| 16492 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16493 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16494 | TestCompletionCallback callback2; |
| 16495 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16496 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16497 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16498 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16499 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16500 | } |
| 16501 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16502 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16503 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16504 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16505 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16506 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16507 | |
| 16508 | // Use two different hosts with different IPs so they don't get pooled. |
| 16509 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 16510 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16511 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16512 | |
| 16513 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16514 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16515 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16516 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16517 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16518 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16519 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16520 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16521 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16522 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16523 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16524 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16525 | spdy::SpdySerializedFrame host1_resp( |
| 16526 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 16527 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16528 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16529 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16530 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16531 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16532 | }; |
| 16533 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16534 | // Use a separate test instance for the separate SpdySession that will be |
| 16535 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16536 | SpdyTestUtil spdy_util_2; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16537 | SequencedSocketData spdy1_data(spdy1_reads, spdy1_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 16538 | session_deps_.socket_factory->AddSocketDataProvider(&spdy1_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16539 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16540 | spdy::SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16541 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16542 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16543 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16544 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16545 | spdy::SpdySerializedFrame host2_resp( |
| 16546 | spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
| 16547 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16548 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16549 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16550 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16551 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16552 | }; |
| 16553 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16554 | SequencedSocketData spdy2_data(spdy2_reads, spdy2_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 16555 | session_deps_.socket_factory->AddSocketDataProvider(&spdy2_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16556 | |
| 16557 | MockWrite http_write[] = { |
| 16558 | MockWrite("GET / HTTP/1.1\r\n" |
| 16559 | "Host: www.a.com\r\n" |
| 16560 | "Connection: keep-alive\r\n\r\n"), |
| 16561 | }; |
| 16562 | |
| 16563 | MockRead http_read[] = { |
| 16564 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16565 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 16566 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16567 | MockRead("hello!"), |
| 16568 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16569 | StaticSocketDataProvider http_data(http_read, http_write); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16570 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16571 | |
| 16572 | HostPortPair host_port_pair_a("www.a.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16573 | SpdySessionKey spdy_session_key_a( |
| 16574 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16575 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16576 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16577 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16578 | |
| 16579 | TestCompletionCallback callback; |
| 16580 | HttpRequestInfo request1; |
| 16581 | request1.method = "GET"; |
| 16582 | request1.url = GURL("https://www.a.com/"); |
| 16583 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16584 | request1.traffic_annotation = |
| 16585 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16586 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16587 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16588 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16589 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16590 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16591 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16592 | |
| 16593 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16594 | ASSERT_TRUE(response); |
| 16595 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16596 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16597 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16598 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16599 | |
| 16600 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16601 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16602 | EXPECT_EQ("hello!", response_data); |
| 16603 | trans.reset(); |
| 16604 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16605 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16606 | |
| 16607 | HostPortPair host_port_pair_b("www.b.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16608 | SpdySessionKey spdy_session_key_b( |
| 16609 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16610 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16611 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16612 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16613 | HttpRequestInfo request2; |
| 16614 | request2.method = "GET"; |
| 16615 | request2.url = GURL("https://www.b.com/"); |
| 16616 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16617 | request2.traffic_annotation = |
| 16618 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16619 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16620 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16621 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16622 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16623 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16624 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16625 | |
| 16626 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16627 | ASSERT_TRUE(response); |
| 16628 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16629 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16630 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16631 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16632 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16633 | EXPECT_EQ("hello!", response_data); |
| 16634 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16635 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16636 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16637 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16638 | |
| 16639 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16640 | SpdySessionKey spdy_session_key_a1( |
| 16641 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16642 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16643 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16644 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16645 | HttpRequestInfo request3; |
| 16646 | request3.method = "GET"; |
| 16647 | request3.url = GURL("http://www.a.com/"); |
| 16648 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16649 | request3.traffic_annotation = |
| 16650 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16651 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16652 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16653 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16654 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16655 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16656 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16657 | |
| 16658 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16659 | ASSERT_TRUE(response); |
| 16660 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16661 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 16662 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16663 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16664 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16665 | EXPECT_EQ("hello!", response_data); |
| 16666 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16667 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16668 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16669 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16670 | } |
| 16671 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16672 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16673 | HttpRequestInfo request; |
| 16674 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16675 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16676 | request.traffic_annotation = |
| 16677 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16678 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16679 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16680 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16681 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16682 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16683 | StaticSocketDataProvider data; |
| 16684 | data.set_connect_data(mock_connect); |
| 16685 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16686 | |
| 16687 | TestCompletionCallback callback; |
| 16688 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16689 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16690 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16691 | |
| 16692 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16693 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16694 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16695 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16696 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16697 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16698 | |
| 16699 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16700 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16701 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16702 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16703 | |
| 16704 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16705 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16706 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16707 | } |
| 16708 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16709 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16710 | HttpRequestInfo request; |
| 16711 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16712 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16713 | request.traffic_annotation = |
| 16714 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16715 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16716 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16717 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16718 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16719 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16720 | StaticSocketDataProvider data; |
| 16721 | data.set_connect_data(mock_connect); |
| 16722 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16723 | |
| 16724 | TestCompletionCallback callback; |
| 16725 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16726 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16727 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16728 | |
| 16729 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16730 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16731 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16732 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16733 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16734 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16735 | |
| 16736 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16737 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16738 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16739 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16740 | |
| 16741 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16742 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16743 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16744 | } |
| 16745 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16746 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16747 | HttpRequestInfo request; |
| 16748 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16749 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16750 | request.traffic_annotation = |
| 16751 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16752 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16753 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16754 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16755 | |
| 16756 | MockWrite data_writes[] = { |
| 16757 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16758 | }; |
| 16759 | MockRead data_reads[] = { |
| 16760 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16761 | }; |
| 16762 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16763 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16764 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16765 | |
| 16766 | TestCompletionCallback callback; |
| 16767 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16768 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16769 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16770 | |
| 16771 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16772 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16773 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16774 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16775 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16776 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16777 | } |
| 16778 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16779 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16780 | HttpRequestInfo request; |
| 16781 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16782 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16783 | request.traffic_annotation = |
| 16784 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16785 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16786 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16787 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16788 | |
| 16789 | MockWrite data_writes[] = { |
| 16790 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 16791 | }; |
| 16792 | MockRead data_reads[] = { |
| 16793 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16794 | }; |
| 16795 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16796 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16797 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16798 | |
| 16799 | TestCompletionCallback callback; |
| 16800 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16801 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16802 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16803 | |
| 16804 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16805 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16806 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16807 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16808 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16809 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16810 | } |
| 16811 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16812 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16813 | HttpRequestInfo request; |
| 16814 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16815 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16816 | request.traffic_annotation = |
| 16817 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16818 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16819 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16820 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16821 | |
| 16822 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16823 | MockWrite( |
| 16824 | "GET / HTTP/1.1\r\n" |
| 16825 | "Host: www.example.org\r\n" |
| 16826 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16827 | }; |
| 16828 | MockRead data_reads[] = { |
| 16829 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16830 | }; |
| 16831 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16832 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16833 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16834 | |
| 16835 | TestCompletionCallback callback; |
| 16836 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16837 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16838 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16839 | |
| 16840 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16841 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16842 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16843 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16844 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16845 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16846 | } |
| 16847 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16848 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16849 | HttpRequestInfo request; |
| 16850 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16851 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16852 | request.traffic_annotation = |
| 16853 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16854 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16855 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16856 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16857 | |
| 16858 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16859 | MockWrite( |
| 16860 | "GET / HTTP/1.1\r\n" |
| 16861 | "Host: www.example.org\r\n" |
| 16862 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16863 | }; |
| 16864 | MockRead data_reads[] = { |
| 16865 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 16866 | }; |
| 16867 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16868 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16869 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16870 | |
| 16871 | TestCompletionCallback callback; |
| 16872 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16873 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16874 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16875 | |
| 16876 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16877 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16878 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16879 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16880 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16881 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16882 | } |
| 16883 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16884 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16885 | HttpRequestInfo request; |
| 16886 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16887 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16888 | request.extra_headers.SetHeader("X-Foo", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16889 | request.traffic_annotation = |
| 16890 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16891 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16892 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16893 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16894 | |
| 16895 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16896 | MockWrite( |
| 16897 | "GET / HTTP/1.1\r\n" |
| 16898 | "Host: www.example.org\r\n" |
| 16899 | "Connection: keep-alive\r\n" |
| 16900 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16901 | }; |
| 16902 | MockRead data_reads[] = { |
| 16903 | MockRead("HTTP/1.1 200 OK\r\n" |
| 16904 | "Content-Length: 5\r\n\r\n" |
| 16905 | "hello"), |
| 16906 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 16907 | }; |
| 16908 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16909 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16910 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16911 | |
| 16912 | TestCompletionCallback callback; |
| 16913 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16914 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16915 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16916 | |
| 16917 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16918 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16919 | |
| 16920 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16921 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16922 | std::string foo; |
| 16923 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 16924 | EXPECT_EQ("bar", foo); |
| 16925 | } |
| 16926 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16927 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 16928 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16929 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16930 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16931 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16932 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16933 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16934 | |
| 16935 | // Set up SSL request. |
| 16936 | |
| 16937 | HttpRequestInfo ssl_request; |
| 16938 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16939 | ssl_request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16940 | ssl_request.traffic_annotation = |
| 16941 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16942 | |
| 16943 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16944 | MockWrite( |
| 16945 | "GET / HTTP/1.1\r\n" |
| 16946 | "Host: www.example.org\r\n" |
| 16947 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16948 | }; |
| 16949 | MockRead ssl_reads[] = { |
| 16950 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16951 | MockRead("Content-Length: 11\r\n\r\n"), |
| 16952 | MockRead("hello world"), |
| 16953 | MockRead(SYNCHRONOUS, OK), |
| 16954 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16955 | StaticSocketDataProvider ssl_data(ssl_reads, ssl_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16956 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16957 | |
| 16958 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16959 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16960 | |
| 16961 | // Set up HTTP request. |
| 16962 | |
| 16963 | HttpRequestInfo http_request; |
| 16964 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16965 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16966 | http_request.traffic_annotation = |
| 16967 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16968 | |
| 16969 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16970 | MockWrite( |
| 16971 | "GET / HTTP/1.1\r\n" |
| 16972 | "Host: www.example.org\r\n" |
| 16973 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16974 | }; |
| 16975 | MockRead http_reads[] = { |
| 16976 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16977 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16978 | MockRead("falafel"), |
| 16979 | MockRead(SYNCHRONOUS, OK), |
| 16980 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16981 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16982 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16983 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16984 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16985 | |
| 16986 | // Start the SSL request. |
| 16987 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16988 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16989 | ASSERT_EQ(ERR_IO_PENDING, |
| 16990 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 16991 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16992 | |
| 16993 | // Start the HTTP request. Pool should stall. |
| 16994 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16995 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16996 | ASSERT_EQ(ERR_IO_PENDING, |
| 16997 | http_trans.Start(&http_request, http_callback.callback(), |
| 16998 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16999 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17000 | |
| 17001 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17002 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17003 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17004 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17005 | EXPECT_EQ("hello world", response_data); |
| 17006 | |
| 17007 | // The SSL socket should automatically be closed, so the HTTP request can |
| 17008 | // start. |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 17009 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17010 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17011 | |
| 17012 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17013 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17014 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17015 | EXPECT_EQ("falafel", response_data); |
| 17016 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17017 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17018 | } |
| 17019 | |
| 17020 | // Tests that when a SSL connection is established but there's no corresponding |
| 17021 | // request that needs it, the new socket is closed if the transport socket pool |
| 17022 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17023 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17024 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17025 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17026 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17027 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17028 | |
| 17029 | // Set up an ssl request. |
| 17030 | |
| 17031 | HttpRequestInfo ssl_request; |
| 17032 | ssl_request.method = "GET"; |
| 17033 | ssl_request.url = GURL("https://www.foopy.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17034 | ssl_request.traffic_annotation = |
| 17035 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17036 | |
| 17037 | // No data will be sent on the SSL socket. |
| 17038 | StaticSocketDataProvider ssl_data; |
| 17039 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17040 | |
| 17041 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17042 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17043 | |
| 17044 | // Set up HTTP request. |
| 17045 | |
| 17046 | HttpRequestInfo http_request; |
| 17047 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17048 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17049 | http_request.traffic_annotation = |
| 17050 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17051 | |
| 17052 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17053 | MockWrite( |
| 17054 | "GET / HTTP/1.1\r\n" |
| 17055 | "Host: www.example.org\r\n" |
| 17056 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17057 | }; |
| 17058 | MockRead http_reads[] = { |
| 17059 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17060 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17061 | MockRead("falafel"), |
| 17062 | MockRead(SYNCHRONOUS, OK), |
| 17063 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17064 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17065 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17066 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17067 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17068 | |
| 17069 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 17070 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 17071 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 17072 | http_stream_factory->PreconnectStreams(1, ssl_request); |
Matt Menke | 9d5e2c9 | 2019-02-05 01:42:23 | [diff] [blame] | 17073 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17074 | |
| 17075 | // Start the HTTP request. Pool should stall. |
| 17076 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17077 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17078 | ASSERT_EQ(ERR_IO_PENDING, |
| 17079 | http_trans.Start(&http_request, http_callback.callback(), |
| 17080 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17081 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17082 | |
| 17083 | // The SSL connection will automatically be closed once the connection is |
| 17084 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17085 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17086 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17087 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17088 | EXPECT_EQ("falafel", response_data); |
| 17089 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17090 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17091 | } |
| 17092 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17093 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17094 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17095 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17096 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17097 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17098 | |
| 17099 | HttpRequestInfo request; |
| 17100 | request.method = "POST"; |
| 17101 | request.url = GURL("http://www.foo.com/"); |
| 17102 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17103 | request.traffic_annotation = |
| 17104 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17105 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17106 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17107 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17108 | // Send headers successfully, but get an error while sending the body. |
| 17109 | MockWrite data_writes[] = { |
| 17110 | MockWrite("POST / HTTP/1.1\r\n" |
| 17111 | "Host: www.foo.com\r\n" |
| 17112 | "Connection: keep-alive\r\n" |
| 17113 | "Content-Length: 3\r\n\r\n"), |
| 17114 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17115 | }; |
| 17116 | |
| 17117 | MockRead data_reads[] = { |
| 17118 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17119 | MockRead("hello world"), |
| 17120 | MockRead(SYNCHRONOUS, OK), |
| 17121 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17122 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17123 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17124 | |
| 17125 | TestCompletionCallback callback; |
| 17126 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17127 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17128 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17129 | |
| 17130 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17131 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17132 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17133 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17134 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17135 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17136 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17137 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17138 | |
| 17139 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17140 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17141 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17142 | EXPECT_EQ("hello world", response_data); |
| 17143 | } |
| 17144 | |
| 17145 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 17146 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17147 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17148 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17149 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17150 | MockWrite data_writes[] = { |
| 17151 | MockWrite("GET / HTTP/1.1\r\n" |
| 17152 | "Host: www.foo.com\r\n" |
| 17153 | "Connection: keep-alive\r\n\r\n"), |
| 17154 | MockWrite("POST / HTTP/1.1\r\n" |
| 17155 | "Host: www.foo.com\r\n" |
| 17156 | "Connection: keep-alive\r\n" |
| 17157 | "Content-Length: 3\r\n\r\n"), |
| 17158 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17159 | }; |
| 17160 | |
| 17161 | MockRead data_reads[] = { |
| 17162 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 17163 | "Content-Length: 14\r\n\r\n"), |
| 17164 | MockRead("first response"), |
| 17165 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 17166 | "Content-Length: 15\r\n\r\n"), |
| 17167 | MockRead("second response"), |
| 17168 | MockRead(SYNCHRONOUS, OK), |
| 17169 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17170 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17171 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17172 | |
| 17173 | TestCompletionCallback callback; |
| 17174 | HttpRequestInfo request1; |
| 17175 | request1.method = "GET"; |
| 17176 | request1.url = GURL("http://www.foo.com/"); |
| 17177 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17178 | request1.traffic_annotation = |
| 17179 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17180 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17181 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17182 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17183 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17184 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17185 | |
| 17186 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17187 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17188 | |
| 17189 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17190 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17191 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17192 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17193 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 17194 | |
| 17195 | std::string response_data1; |
| 17196 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17197 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17198 | EXPECT_EQ("first response", response_data1); |
| 17199 | // Delete the transaction to release the socket back into the socket pool. |
| 17200 | trans1.reset(); |
| 17201 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17202 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17203 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17204 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17205 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17206 | |
| 17207 | HttpRequestInfo request2; |
| 17208 | request2.method = "POST"; |
| 17209 | request2.url = GURL("http://www.foo.com/"); |
| 17210 | request2.upload_data_stream = &upload_data_stream; |
| 17211 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17212 | request2.traffic_annotation = |
| 17213 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17214 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17215 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17216 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17217 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17218 | |
| 17219 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17220 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17221 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17222 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17223 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17224 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17225 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17226 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 17227 | |
| 17228 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17229 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17230 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17231 | EXPECT_EQ("second response", response_data2); |
| 17232 | } |
| 17233 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17234 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17235 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17236 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17237 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17238 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17239 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17240 | |
| 17241 | HttpRequestInfo request; |
| 17242 | request.method = "POST"; |
| 17243 | request.url = GURL("http://www.foo.com/"); |
| 17244 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17245 | request.traffic_annotation = |
| 17246 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17247 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17248 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17249 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17250 | // Send headers successfully, but get an error while sending the body. |
| 17251 | MockWrite data_writes[] = { |
| 17252 | MockWrite("POST / HTTP/1.1\r\n" |
| 17253 | "Host: www.foo.com\r\n" |
| 17254 | "Connection: keep-alive\r\n" |
| 17255 | "Content-Length: 3\r\n\r\n" |
| 17256 | "fo"), |
| 17257 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17258 | }; |
| 17259 | |
| 17260 | MockRead data_reads[] = { |
| 17261 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17262 | MockRead("hello world"), |
| 17263 | MockRead(SYNCHRONOUS, OK), |
| 17264 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17265 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17266 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17267 | |
| 17268 | TestCompletionCallback callback; |
| 17269 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17270 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17271 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17272 | |
| 17273 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17274 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17275 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17276 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17277 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17278 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17279 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17280 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17281 | |
| 17282 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17283 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17284 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17285 | EXPECT_EQ("hello world", response_data); |
| 17286 | } |
| 17287 | |
| 17288 | // This tests the more common case than the previous test, where headers and |
| 17289 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17290 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17291 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17292 | |
| 17293 | HttpRequestInfo request; |
| 17294 | request.method = "POST"; |
| 17295 | request.url = GURL("http://www.foo.com/"); |
| 17296 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17297 | request.traffic_annotation = |
| 17298 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17299 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17300 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17301 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17302 | // Send headers successfully, but get an error while sending the body. |
| 17303 | MockWrite data_writes[] = { |
| 17304 | MockWrite("POST / HTTP/1.1\r\n" |
| 17305 | "Host: www.foo.com\r\n" |
| 17306 | "Connection: keep-alive\r\n" |
| 17307 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17308 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17309 | }; |
| 17310 | |
| 17311 | MockRead data_reads[] = { |
| 17312 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17313 | MockRead("hello world"), |
| 17314 | MockRead(SYNCHRONOUS, OK), |
| 17315 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17316 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17317 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17318 | |
| 17319 | TestCompletionCallback callback; |
| 17320 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17321 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17322 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17323 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 17324 | // they can't be merged with the body in a single send. Not currently |
| 17325 | // necessary since a chunked body is never merged with headers, but this makes |
| 17326 | // the test more future proof. |
| 17327 | base::RunLoop().RunUntilIdle(); |
| 17328 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17329 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17330 | |
| 17331 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17332 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17333 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17334 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17335 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17336 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17337 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17338 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17339 | |
| 17340 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17341 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17342 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17343 | EXPECT_EQ("hello world", response_data); |
| 17344 | } |
| 17345 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17346 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17347 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17348 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17349 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17350 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17351 | |
| 17352 | HttpRequestInfo request; |
| 17353 | request.method = "POST"; |
| 17354 | request.url = GURL("http://www.foo.com/"); |
| 17355 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17356 | request.traffic_annotation = |
| 17357 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17358 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17359 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17360 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17361 | |
| 17362 | MockWrite data_writes[] = { |
| 17363 | MockWrite("POST / HTTP/1.1\r\n" |
| 17364 | "Host: www.foo.com\r\n" |
| 17365 | "Connection: keep-alive\r\n" |
| 17366 | "Content-Length: 3\r\n\r\n"), |
| 17367 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17368 | }; |
| 17369 | |
| 17370 | MockRead data_reads[] = { |
| 17371 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17372 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17373 | MockRead("hello world"), |
| 17374 | MockRead(SYNCHRONOUS, OK), |
| 17375 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17376 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17377 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17378 | |
| 17379 | TestCompletionCallback callback; |
| 17380 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17381 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17382 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17383 | |
| 17384 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17385 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17386 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17387 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17388 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17389 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17390 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17391 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17392 | |
| 17393 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17394 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17395 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17396 | EXPECT_EQ("hello world", response_data); |
| 17397 | } |
| 17398 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17399 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17400 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17401 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17402 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17403 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17404 | |
| 17405 | HttpRequestInfo request; |
| 17406 | request.method = "POST"; |
| 17407 | request.url = GURL("http://www.foo.com/"); |
| 17408 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17409 | request.traffic_annotation = |
| 17410 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17411 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17412 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17413 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17414 | // Send headers successfully, but get an error while sending the body. |
| 17415 | MockWrite data_writes[] = { |
| 17416 | MockWrite("POST / HTTP/1.1\r\n" |
| 17417 | "Host: www.foo.com\r\n" |
| 17418 | "Connection: keep-alive\r\n" |
| 17419 | "Content-Length: 3\r\n\r\n"), |
| 17420 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17421 | }; |
| 17422 | |
| 17423 | MockRead data_reads[] = { |
| 17424 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 17425 | MockRead("hello world"), |
| 17426 | MockRead(SYNCHRONOUS, OK), |
| 17427 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17428 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17429 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17430 | |
| 17431 | TestCompletionCallback callback; |
| 17432 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17433 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17434 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17435 | |
| 17436 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17437 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17438 | } |
| 17439 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17440 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17441 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17442 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17443 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17444 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17445 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17446 | |
| 17447 | HttpRequestInfo request; |
| 17448 | request.method = "POST"; |
| 17449 | request.url = GURL("http://www.foo.com/"); |
| 17450 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17451 | request.traffic_annotation = |
| 17452 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17453 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17454 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17455 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17456 | // Send headers successfully, but get an error while sending the body. |
| 17457 | MockWrite data_writes[] = { |
| 17458 | MockWrite("POST / HTTP/1.1\r\n" |
| 17459 | "Host: www.foo.com\r\n" |
| 17460 | "Connection: keep-alive\r\n" |
| 17461 | "Content-Length: 3\r\n\r\n"), |
| 17462 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17463 | }; |
| 17464 | |
| 17465 | MockRead data_reads[] = { |
| 17466 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17467 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 17468 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 17469 | MockRead("Content-Length: 0\r\n\r\n"), |
| 17470 | MockRead(SYNCHRONOUS, OK), |
| 17471 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17472 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17473 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17474 | |
| 17475 | TestCompletionCallback callback; |
| 17476 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17477 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17478 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17479 | |
| 17480 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17481 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17482 | } |
| 17483 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17484 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17485 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17486 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17487 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17488 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17489 | |
| 17490 | HttpRequestInfo request; |
| 17491 | request.method = "POST"; |
| 17492 | request.url = GURL("http://www.foo.com/"); |
| 17493 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17494 | request.traffic_annotation = |
| 17495 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17496 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17497 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17498 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17499 | // Send headers successfully, but get an error while sending the body. |
| 17500 | MockWrite data_writes[] = { |
| 17501 | MockWrite("POST / HTTP/1.1\r\n" |
| 17502 | "Host: www.foo.com\r\n" |
| 17503 | "Connection: keep-alive\r\n" |
| 17504 | "Content-Length: 3\r\n\r\n"), |
| 17505 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17506 | }; |
| 17507 | |
| 17508 | MockRead data_reads[] = { |
| 17509 | MockRead("HTTP 0.9 rocks!"), |
| 17510 | MockRead(SYNCHRONOUS, OK), |
| 17511 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17512 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17513 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17514 | |
| 17515 | TestCompletionCallback callback; |
| 17516 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17517 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17518 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17519 | |
| 17520 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17521 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17522 | } |
| 17523 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17524 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17525 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17526 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17527 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17528 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17529 | |
| 17530 | HttpRequestInfo request; |
| 17531 | request.method = "POST"; |
| 17532 | request.url = GURL("http://www.foo.com/"); |
| 17533 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17534 | request.traffic_annotation = |
| 17535 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17536 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17537 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17538 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17539 | // Send headers successfully, but get an error while sending the body. |
| 17540 | MockWrite data_writes[] = { |
| 17541 | MockWrite("POST / HTTP/1.1\r\n" |
| 17542 | "Host: www.foo.com\r\n" |
| 17543 | "Connection: keep-alive\r\n" |
| 17544 | "Content-Length: 3\r\n\r\n"), |
| 17545 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17546 | }; |
| 17547 | |
| 17548 | MockRead data_reads[] = { |
| 17549 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 17550 | MockRead(SYNCHRONOUS, OK), |
| 17551 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17552 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17553 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17554 | |
| 17555 | TestCompletionCallback callback; |
| 17556 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17557 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17558 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17559 | |
| 17560 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17561 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17562 | } |
| 17563 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17564 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17565 | |
| 17566 | namespace { |
| 17567 | |
| 17568 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
| 17569 | headers->SetHeader("Connection", "Upgrade"); |
| 17570 | headers->SetHeader("Upgrade", "websocket"); |
| 17571 | headers->SetHeader("Origin", "http://www.example.org"); |
| 17572 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17573 | } |
| 17574 | |
| 17575 | } // namespace |
| 17576 | |
| 17577 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17578 | for (bool secure : {true, false}) { |
| 17579 | MockWrite data_writes[] = { |
| 17580 | MockWrite("GET / HTTP/1.1\r\n" |
| 17581 | "Host: www.example.org\r\n" |
| 17582 | "Connection: Upgrade\r\n" |
| 17583 | "Upgrade: websocket\r\n" |
| 17584 | "Origin: http://www.example.org\r\n" |
| 17585 | "Sec-WebSocket-Version: 13\r\n" |
| 17586 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17587 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17588 | "client_max_window_bits\r\n\r\n")}; |
| 17589 | |
| 17590 | MockRead data_reads[] = { |
| 17591 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17592 | "Upgrade: websocket\r\n" |
| 17593 | "Connection: Upgrade\r\n" |
| 17594 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
| 17595 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17596 | StaticSocketDataProvider data(data_reads, data_writes); |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17597 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17598 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17599 | if (secure) |
| 17600 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17601 | |
| 17602 | HttpRequestInfo request; |
| 17603 | request.method = "GET"; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17604 | request.url = |
| 17605 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 17606 | AddWebSocketHeaders(&request.extra_headers); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17607 | request.traffic_annotation = |
| 17608 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17609 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17610 | TestWebSocketHandshakeStreamCreateHelper |
| 17611 | websocket_handshake_stream_create_helper; |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17612 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17613 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17614 | HttpNetworkTransaction trans(LOW, session.get()); |
| 17615 | trans.SetWebSocketHandshakeStreamCreateHelper( |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17616 | &websocket_handshake_stream_create_helper); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17617 | |
| 17618 | TestCompletionCallback callback; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17619 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17620 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17621 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17622 | const HttpStreamRequest* stream_request = trans.stream_request_.get(); |
| 17623 | ASSERT_TRUE(stream_request); |
| 17624 | EXPECT_EQ(&websocket_handshake_stream_create_helper, |
| 17625 | stream_request->websocket_handshake_stream_create_helper()); |
| 17626 | |
| 17627 | rv = callback.WaitForResult(); |
| 17628 | EXPECT_THAT(rv, IsOk()); |
| 17629 | |
| 17630 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 17631 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17632 | } |
| 17633 | } |
| 17634 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17635 | // Verify that proxy headers are not sent to the destination server when |
| 17636 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17637 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17638 | HttpRequestInfo request; |
| 17639 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17640 | request.url = GURL("wss://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17641 | request.traffic_annotation = |
| 17642 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17643 | AddWebSocketHeaders(&request.extra_headers); |
| 17644 | |
| 17645 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17646 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17647 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17648 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17649 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17650 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17651 | |
| 17652 | // Since a proxy is configured, try to establish a tunnel. |
| 17653 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17654 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17655 | "Host: www.example.org:443\r\n" |
| 17656 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17657 | |
| 17658 | // After calling trans->RestartWithAuth(), this is the request we should |
| 17659 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17660 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17661 | "Host: www.example.org:443\r\n" |
| 17662 | "Proxy-Connection: keep-alive\r\n" |
| 17663 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17664 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17665 | MockWrite("GET / HTTP/1.1\r\n" |
| 17666 | "Host: www.example.org\r\n" |
| 17667 | "Connection: Upgrade\r\n" |
| 17668 | "Upgrade: websocket\r\n" |
| 17669 | "Origin: http://www.example.org\r\n" |
| 17670 | "Sec-WebSocket-Version: 13\r\n" |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17671 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17672 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17673 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17674 | |
| 17675 | // The proxy responds to the connect with a 407, using a persistent |
| 17676 | // connection. |
| 17677 | MockRead data_reads[] = { |
| 17678 | // No credentials. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17679 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 17680 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 17681 | "Content-Length: 0\r\n" |
| 17682 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17683 | |
| 17684 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17685 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17686 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17687 | "Upgrade: websocket\r\n" |
| 17688 | "Connection: Upgrade\r\n" |
| 17689 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17690 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17691 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17692 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17693 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17694 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17695 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17696 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17697 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17698 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17699 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17700 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17701 | &websocket_stream_create_helper); |
| 17702 | |
| 17703 | { |
| 17704 | TestCompletionCallback callback; |
| 17705 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17706 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17707 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17708 | |
| 17709 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17710 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17711 | } |
| 17712 | |
| 17713 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17714 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17715 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17716 | EXPECT_EQ(407, response->headers->response_code()); |
| 17717 | |
| 17718 | { |
| 17719 | TestCompletionCallback callback; |
| 17720 | |
| 17721 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 17722 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17723 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17724 | |
| 17725 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17726 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17727 | } |
| 17728 | |
| 17729 | response = trans->GetResponseInfo(); |
| 17730 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17731 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17732 | |
| 17733 | EXPECT_EQ(101, response->headers->response_code()); |
| 17734 | |
| 17735 | trans.reset(); |
| 17736 | session->CloseAllConnections(); |
| 17737 | } |
| 17738 | |
| 17739 | // Verify that proxy headers are not sent to the destination server when |
| 17740 | // establishing a tunnel for an insecure WebSocket connection. |
| 17741 | // This requires the authentication info to be injected into the auth cache |
| 17742 | // due to crbug.com/395064 |
| 17743 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17744 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17745 | HttpRequestInfo request; |
| 17746 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17747 | request.url = GURL("ws://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17748 | request.traffic_annotation = |
| 17749 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17750 | AddWebSocketHeaders(&request.extra_headers); |
| 17751 | |
| 17752 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17753 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17754 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17755 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17756 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17757 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17758 | |
| 17759 | MockWrite data_writes[] = { |
| 17760 | // Try to establish a tunnel for the WebSocket connection, with |
| 17761 | // credentials. Because WebSockets have a separate set of socket pools, |
| 17762 | // they cannot and will not use the same TCP/IP connection as the |
| 17763 | // preflight HTTP request. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17764 | MockWrite("CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 17765 | "Host: www.example.org:80\r\n" |
| 17766 | "Proxy-Connection: keep-alive\r\n" |
| 17767 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17768 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17769 | MockWrite("GET / HTTP/1.1\r\n" |
| 17770 | "Host: www.example.org\r\n" |
| 17771 | "Connection: Upgrade\r\n" |
| 17772 | "Upgrade: websocket\r\n" |
| 17773 | "Origin: http://www.example.org\r\n" |
| 17774 | "Sec-WebSocket-Version: 13\r\n" |
| 17775 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17776 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17777 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17778 | |
| 17779 | MockRead data_reads[] = { |
| 17780 | // HTTP CONNECT with credentials. |
| 17781 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17782 | |
| 17783 | // WebSocket connection established inside tunnel. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17784 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17785 | "Upgrade: websocket\r\n" |
| 17786 | "Connection: Upgrade\r\n" |
| 17787 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17788 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17789 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17790 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17791 | |
| 17792 | session->http_auth_cache()->Add( |
| 17793 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 17794 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 17795 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17796 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17797 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17798 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17799 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17800 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17801 | &websocket_stream_create_helper); |
| 17802 | |
| 17803 | TestCompletionCallback callback; |
| 17804 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17805 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17806 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17807 | |
| 17808 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17809 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17810 | |
| 17811 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17812 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17813 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17814 | |
| 17815 | EXPECT_EQ(101, response->headers->response_code()); |
| 17816 | |
| 17817 | trans.reset(); |
| 17818 | session->CloseAllConnections(); |
| 17819 | } |
| 17820 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17821 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17822 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17823 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17824 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17825 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17826 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17827 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17828 | |
| 17829 | HttpRequestInfo request; |
| 17830 | request.method = "POST"; |
| 17831 | request.url = GURL("http://www.foo.com/"); |
| 17832 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17833 | request.traffic_annotation = |
| 17834 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17835 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17836 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17837 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17838 | MockWrite data_writes[] = { |
| 17839 | MockWrite("POST / HTTP/1.1\r\n" |
| 17840 | "Host: www.foo.com\r\n" |
| 17841 | "Connection: keep-alive\r\n" |
| 17842 | "Content-Length: 3\r\n\r\n"), |
| 17843 | MockWrite("foo"), |
| 17844 | }; |
| 17845 | |
| 17846 | MockRead data_reads[] = { |
| 17847 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17848 | MockRead(SYNCHRONOUS, OK), |
| 17849 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17850 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17851 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17852 | |
| 17853 | TestCompletionCallback callback; |
| 17854 | |
| 17855 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17856 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17857 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17858 | |
| 17859 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17860 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17861 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17862 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 17863 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17864 | } |
| 17865 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17866 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17867 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17868 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17869 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17870 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17871 | |
| 17872 | HttpRequestInfo request; |
| 17873 | request.method = "POST"; |
| 17874 | request.url = GURL("http://www.foo.com/"); |
| 17875 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17876 | request.traffic_annotation = |
| 17877 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17878 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17879 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17880 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17881 | MockWrite data_writes[] = { |
| 17882 | MockWrite("POST / HTTP/1.1\r\n" |
| 17883 | "Host: www.foo.com\r\n" |
| 17884 | "Connection: keep-alive\r\n" |
| 17885 | "Content-Length: 3\r\n\r\n"), |
| 17886 | MockWrite("foo"), |
| 17887 | }; |
| 17888 | |
| 17889 | MockRead data_reads[] = { |
| 17890 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 17891 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17892 | MockRead(SYNCHRONOUS, OK), |
| 17893 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17894 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17895 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17896 | |
| 17897 | TestCompletionCallback callback; |
| 17898 | |
| 17899 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17900 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17901 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17902 | |
| 17903 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17904 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17905 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17906 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 17907 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17908 | } |
| 17909 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17910 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17911 | ChunkedUploadDataStream upload_data_stream(0); |
| 17912 | |
| 17913 | HttpRequestInfo request; |
| 17914 | request.method = "POST"; |
| 17915 | request.url = GURL("http://www.foo.com/"); |
| 17916 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17917 | request.traffic_annotation = |
| 17918 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17919 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17920 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17921 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17922 | // Send headers successfully, but get an error while sending the body. |
| 17923 | MockWrite data_writes[] = { |
| 17924 | MockWrite("POST / HTTP/1.1\r\n" |
| 17925 | "Host: www.foo.com\r\n" |
| 17926 | "Connection: keep-alive\r\n" |
| 17927 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17928 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 17929 | }; |
| 17930 | |
| 17931 | MockRead data_reads[] = { |
| 17932 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17933 | MockRead(SYNCHRONOUS, OK), |
| 17934 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17935 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17936 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17937 | |
| 17938 | TestCompletionCallback callback; |
| 17939 | |
| 17940 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17941 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17942 | |
| 17943 | base::RunLoop().RunUntilIdle(); |
| 17944 | upload_data_stream.AppendData("f", 1, false); |
| 17945 | |
| 17946 | base::RunLoop().RunUntilIdle(); |
| 17947 | upload_data_stream.AppendData("oo", 2, true); |
| 17948 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17949 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17950 | |
| 17951 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17952 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17953 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17954 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 17955 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17956 | } |
| 17957 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17958 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 17959 | const std::string& accept_encoding, |
| 17960 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17961 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17962 | bool should_match) { |
| 17963 | HttpRequestInfo request; |
| 17964 | request.method = "GET"; |
| 17965 | request.url = GURL("http://www.foo.com/"); |
| 17966 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 17967 | accept_encoding); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17968 | request.traffic_annotation = |
| 17969 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17970 | |
| 17971 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 17972 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17973 | // Send headers successfully, but get an error while sending the body. |
| 17974 | MockWrite data_writes[] = { |
| 17975 | MockWrite("GET / HTTP/1.1\r\n" |
| 17976 | "Host: www.foo.com\r\n" |
| 17977 | "Connection: keep-alive\r\n" |
| 17978 | "Accept-Encoding: "), |
| 17979 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 17980 | }; |
| 17981 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17982 | std::string response_code = "200 OK"; |
| 17983 | std::string extra; |
| 17984 | if (!location.empty()) { |
| 17985 | response_code = "301 Redirect\r\nLocation: "; |
| 17986 | response_code.append(location); |
| 17987 | } |
| 17988 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17989 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17990 | MockRead("HTTP/1.0 "), |
| 17991 | MockRead(response_code.data()), |
| 17992 | MockRead("\r\nContent-Encoding: "), |
| 17993 | MockRead(content_encoding.data()), |
| 17994 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17995 | MockRead(SYNCHRONOUS, OK), |
| 17996 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17997 | StaticSocketDataProvider data(data_reads, data_writes); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17998 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 17999 | |
| 18000 | TestCompletionCallback callback; |
| 18001 | |
| 18002 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18003 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18004 | |
| 18005 | rv = callback.WaitForResult(); |
| 18006 | if (should_match) { |
| 18007 | EXPECT_THAT(rv, IsOk()); |
| 18008 | } else { |
| 18009 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 18010 | } |
| 18011 | } |
| 18012 | |
| 18013 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18014 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18015 | } |
| 18016 | |
| 18017 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18018 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 18019 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18020 | } |
| 18021 | |
| 18022 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 18023 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18024 | "", false); |
| 18025 | } |
| 18026 | |
| 18027 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 18028 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 18029 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18030 | } |
| 18031 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18032 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 18033 | ProxyConfig proxy_config; |
| 18034 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18035 | proxy_config.set_pac_mandatory(true); |
| 18036 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18037 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18038 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18039 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 18040 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18041 | |
| 18042 | HttpRequestInfo request; |
| 18043 | request.method = "GET"; |
| 18044 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18045 | request.traffic_annotation = |
| 18046 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18047 | |
| 18048 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18049 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18050 | |
| 18051 | TestCompletionCallback callback; |
| 18052 | |
| 18053 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18054 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18055 | EXPECT_THAT(callback.WaitForResult(), |
| 18056 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18057 | } |
| 18058 | |
| 18059 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 18060 | ProxyConfig proxy_config; |
| 18061 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18062 | proxy_config.set_pac_mandatory(true); |
| 18063 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 18064 | new MockAsyncProxyResolverFactory(false); |
| 18065 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18066 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18067 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18068 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18069 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18070 | HttpRequestInfo request; |
| 18071 | request.method = "GET"; |
| 18072 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18073 | request.traffic_annotation = |
| 18074 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18075 | |
| 18076 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18077 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18078 | |
| 18079 | TestCompletionCallback callback; |
| 18080 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18081 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18082 | |
| 18083 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 18084 | ERR_FAILED, &resolver); |
| 18085 | EXPECT_THAT(callback.WaitForResult(), |
| 18086 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18087 | } |
| 18088 | |
| 18089 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18090 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18091 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18092 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18093 | session_deps_.enable_quic = false; |
| 18094 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18095 | |
| 18096 | HttpRequestInfo request; |
| 18097 | request.method = "GET"; |
| 18098 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18099 | request.traffic_annotation = |
| 18100 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18101 | |
| 18102 | TestCompletionCallback callback; |
| 18103 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18104 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18105 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18106 | |
| 18107 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 18108 | } |
| 18109 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18110 | //----------------------------------------------------------------------------- |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18111 | // Reporting tests |
| 18112 | |
| 18113 | #if BUILDFLAG(ENABLE_REPORTING) |
| 18114 | class HttpNetworkTransactionReportingTest : public HttpNetworkTransactionTest { |
| 18115 | protected: |
| 18116 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18117 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18118 | auto test_reporting_context = std::make_unique<TestReportingContext>( |
| 18119 | &clock_, &tick_clock_, ReportingPolicy()); |
| 18120 | test_reporting_context_ = test_reporting_context.get(); |
| 18121 | session_deps_.reporting_service = |
| 18122 | ReportingService::CreateForTesting(std::move(test_reporting_context)); |
| 18123 | } |
| 18124 | |
| 18125 | TestReportingContext* reporting_context() const { |
| 18126 | return test_reporting_context_; |
| 18127 | } |
| 18128 | |
| 18129 | void clear_reporting_service() { |
| 18130 | session_deps_.reporting_service.reset(); |
| 18131 | test_reporting_context_ = nullptr; |
| 18132 | } |
| 18133 | |
| 18134 | // Makes an HTTPS request that should install a valid Reporting policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18135 | void RequestPolicy(CertStatus cert_status = 0) { |
| 18136 | HttpRequestInfo request; |
| 18137 | request.method = "GET"; |
| 18138 | request.url = GURL(url_); |
| 18139 | request.traffic_annotation = |
| 18140 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18141 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18142 | MockRead data_reads[] = { |
| 18143 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18144 | MockRead("Report-To: {\"group\": \"nel\", \"max_age\": 86400, " |
| 18145 | "\"endpoints\": [{\"url\": " |
| 18146 | "\"https://www.example.org/upload/\"}]}\r\n"), |
| 18147 | MockRead("\r\n"), |
| 18148 | MockRead("hello world"), |
| 18149 | MockRead(SYNCHRONOUS, OK), |
| 18150 | }; |
| 18151 | MockWrite data_writes[] = { |
| 18152 | MockWrite("GET / HTTP/1.1\r\n" |
| 18153 | "Host: www.example.org\r\n" |
| 18154 | "Connection: keep-alive\r\n\r\n"), |
| 18155 | }; |
| 18156 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18157 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18158 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18159 | |
| 18160 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18161 | if (request.url.SchemeIsCryptographic()) { |
| 18162 | ssl.ssl_info.cert = |
| 18163 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18164 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18165 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18166 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18167 | } |
| 18168 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18169 | TestCompletionCallback callback; |
| 18170 | auto session = CreateSession(&session_deps_); |
| 18171 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18172 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18173 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18174 | } |
| 18175 | |
| 18176 | protected: |
| 18177 | std::string url_ = "https://www.example.org/"; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18178 | |
| 18179 | private: |
| 18180 | TestReportingContext* test_reporting_context_; |
| 18181 | }; |
| 18182 | |
| 18183 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18184 | DontProcessReportToHeaderNoService) { |
| 18185 | base::HistogramTester histograms; |
| 18186 | clear_reporting_service(); |
| 18187 | RequestPolicy(); |
| 18188 | histograms.ExpectBucketCount( |
| 18189 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18190 | ReportingHeaderParser::HeaderOutcome::DISCARDED_NO_REPORTING_SERVICE, 1); |
| 18191 | } |
| 18192 | |
| 18193 | TEST_F(HttpNetworkTransactionReportingTest, DontProcessReportToHeaderHttp) { |
| 18194 | base::HistogramTester histograms; |
| 18195 | url_ = "http://www.example.org/"; |
| 18196 | RequestPolicy(); |
| 18197 | histograms.ExpectBucketCount( |
| 18198 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18199 | ReportingHeaderParser::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18200 | } |
| 18201 | |
| 18202 | TEST_F(HttpNetworkTransactionReportingTest, ProcessReportToHeaderHttps) { |
| 18203 | RequestPolicy(); |
| 18204 | std::vector<const ReportingClient*> clients; |
| 18205 | reporting_context()->cache()->GetClients(&clients); |
| 18206 | ASSERT_EQ(1u, clients.size()); |
| 18207 | const auto* client = clients[0]; |
| 18208 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 18209 | client->origin); |
| 18210 | EXPECT_EQ(GURL("https://www.example.org/upload/"), client->endpoint); |
| 18211 | EXPECT_EQ("nel", client->group); |
| 18212 | } |
| 18213 | |
| 18214 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18215 | DontProcessReportToHeaderInvalidHttps) { |
| 18216 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18217 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18218 | RequestPolicy(cert_status); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18219 | histograms.ExpectBucketCount( |
| 18220 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18221 | ReportingHeaderParser::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, 1); |
| 18222 | } |
| 18223 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 18224 | |
| 18225 | //----------------------------------------------------------------------------- |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18226 | // Network Error Logging tests |
| 18227 | |
| 18228 | #if BUILDFLAG(ENABLE_REPORTING) |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18229 | namespace { |
| 18230 | |
| 18231 | const char kUserAgent[] = "Mozilla/1.0"; |
| 18232 | const char kReferrer[] = "https://www.referrer.org/"; |
| 18233 | |
| 18234 | } // namespace |
| 18235 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18236 | class HttpNetworkTransactionNetworkErrorLoggingTest |
| 18237 | : public HttpNetworkTransactionTest { |
| 18238 | protected: |
| 18239 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18240 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18241 | auto network_error_logging_service = |
| 18242 | std::make_unique<TestNetworkErrorLoggingService>(); |
| 18243 | test_network_error_logging_service_ = network_error_logging_service.get(); |
| 18244 | session_deps_.network_error_logging_service = |
| 18245 | std::move(network_error_logging_service); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18246 | |
| 18247 | extra_headers_.SetHeader("User-Agent", kUserAgent); |
| 18248 | extra_headers_.SetHeader("Referer", kReferrer); |
| 18249 | |
| 18250 | request_.method = "GET"; |
| 18251 | request_.url = GURL(url_); |
| 18252 | request_.extra_headers = extra_headers_; |
| 18253 | request_.reporting_upload_depth = reporting_upload_depth_; |
| 18254 | request_.traffic_annotation = |
| 18255 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18256 | } |
| 18257 | |
| 18258 | TestNetworkErrorLoggingService* network_error_logging_service() const { |
| 18259 | return test_network_error_logging_service_; |
| 18260 | } |
| 18261 | |
| 18262 | void clear_network_error_logging_service() { |
| 18263 | session_deps_.network_error_logging_service.reset(); |
| 18264 | test_network_error_logging_service_ = nullptr; |
| 18265 | } |
| 18266 | |
| 18267 | // Makes an HTTPS request that should install a valid NEL policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18268 | void RequestPolicy(CertStatus cert_status = 0) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18269 | std::string extra_header_string = extra_headers_.ToString(); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18270 | MockRead data_reads[] = { |
| 18271 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18272 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18273 | MockRead("\r\n"), |
| 18274 | MockRead("hello world"), |
| 18275 | MockRead(SYNCHRONOUS, OK), |
| 18276 | }; |
| 18277 | MockWrite data_writes[] = { |
| 18278 | MockWrite("GET / HTTP/1.1\r\n" |
| 18279 | "Host: www.example.org\r\n" |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18280 | "Connection: keep-alive\r\n"), |
| 18281 | MockWrite(ASYNC, extra_header_string.data(), |
| 18282 | extra_header_string.size()), |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18283 | }; |
| 18284 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18285 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18286 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18287 | |
| 18288 | SSLSocketDataProvider ssl(ASYNC, OK); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18289 | if (request_.url.SchemeIsCryptographic()) { |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18290 | ssl.ssl_info.cert = |
| 18291 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18292 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18293 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18294 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18295 | } |
| 18296 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18297 | TestCompletionCallback callback; |
| 18298 | auto session = CreateSession(&session_deps_); |
| 18299 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18300 | int rv = trans.Start(&request_, callback.callback(), NetLogWithSource()); |
| 18301 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18302 | |
| 18303 | std::string response_data; |
| 18304 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 18305 | EXPECT_EQ("hello world", response_data); |
| 18306 | } |
| 18307 | |
| 18308 | void CheckReport(size_t index, |
| 18309 | int status_code, |
| 18310 | int error_type, |
| 18311 | IPAddress server_ip = IPAddress::IPv4Localhost()) { |
| 18312 | ASSERT_LT(index, network_error_logging_service()->errors().size()); |
| 18313 | |
| 18314 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18315 | network_error_logging_service()->errors()[index]; |
| 18316 | EXPECT_EQ(url_, error.uri); |
| 18317 | EXPECT_EQ(kReferrer, error.referrer); |
| 18318 | EXPECT_EQ(kUserAgent, error.user_agent); |
| 18319 | EXPECT_EQ(server_ip, error.server_ip); |
| 18320 | EXPECT_EQ("http/1.1", error.protocol); |
| 18321 | EXPECT_EQ("GET", error.method); |
| 18322 | EXPECT_EQ(status_code, error.status_code); |
| 18323 | EXPECT_EQ(error_type, error.type); |
| 18324 | EXPECT_EQ(0, error.reporting_upload_depth); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18325 | } |
| 18326 | |
| 18327 | protected: |
| 18328 | std::string url_ = "https://www.example.org/"; |
| 18329 | CertStatus cert_status_ = 0; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18330 | HttpRequestInfo request_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18331 | HttpRequestHeaders extra_headers_; |
| 18332 | int reporting_upload_depth_ = 0; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18333 | |
| 18334 | private: |
| 18335 | TestNetworkErrorLoggingService* test_network_error_logging_service_; |
| 18336 | }; |
| 18337 | |
| 18338 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18339 | DontProcessNelHeaderNoService) { |
| 18340 | base::HistogramTester histograms; |
| 18341 | clear_network_error_logging_service(); |
| 18342 | RequestPolicy(); |
| 18343 | histograms.ExpectBucketCount( |
| 18344 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18345 | NetworkErrorLoggingService::HeaderOutcome:: |
| 18346 | DISCARDED_NO_NETWORK_ERROR_LOGGING_SERVICE, |
| 18347 | 1); |
| 18348 | } |
| 18349 | |
| 18350 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18351 | DontProcessNelHeaderHttp) { |
| 18352 | base::HistogramTester histograms; |
| 18353 | url_ = "http://www.example.org/"; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18354 | request_.url = GURL(url_); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18355 | RequestPolicy(); |
| 18356 | histograms.ExpectBucketCount( |
| 18357 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18358 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18359 | } |
| 18360 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 18361 | // Don't set NEL policies received on a proxied connection. |
| 18362 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18363 | DontProcessNelHeaderProxy) { |
| 18364 | session_deps_.proxy_resolution_service = |
| 18365 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18366 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18367 | BoundTestNetLog log; |
| 18368 | session_deps_.net_log = log.bound().net_log(); |
| 18369 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18370 | |
| 18371 | HttpRequestInfo request; |
| 18372 | request.method = "GET"; |
| 18373 | request.url = GURL("https://www.example.org/"); |
| 18374 | request.traffic_annotation = |
| 18375 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18376 | |
| 18377 | // Since we have proxy, should try to establish tunnel. |
| 18378 | MockWrite data_writes1[] = { |
| 18379 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 18380 | "Host: www.example.org:443\r\n" |
| 18381 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 18382 | |
| 18383 | MockWrite("GET / HTTP/1.1\r\n" |
| 18384 | "Host: www.example.org\r\n" |
| 18385 | "Connection: keep-alive\r\n\r\n"), |
| 18386 | }; |
| 18387 | |
| 18388 | MockRead data_reads1[] = { |
| 18389 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 18390 | |
| 18391 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 18392 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18393 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18394 | MockRead("Content-Length: 100\r\n\r\n"), |
| 18395 | MockRead(SYNCHRONOUS, OK), |
| 18396 | }; |
| 18397 | |
| 18398 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18399 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18400 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18401 | ssl.ssl_info.cert = |
| 18402 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18403 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 18404 | ssl.ssl_info.cert_status = 0; |
| 18405 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18406 | |
| 18407 | TestCompletionCallback callback1; |
| 18408 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18409 | |
| 18410 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
| 18411 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18412 | |
| 18413 | rv = callback1.WaitForResult(); |
| 18414 | EXPECT_THAT(rv, IsOk()); |
| 18415 | |
| 18416 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 18417 | ASSERT_TRUE(response); |
| 18418 | EXPECT_EQ(200, response->headers->response_code()); |
| 18419 | EXPECT_TRUE(response->was_fetched_via_proxy); |
| 18420 | |
| 18421 | // No NEL header was set. |
| 18422 | EXPECT_EQ(0u, network_error_logging_service()->headers().size()); |
| 18423 | } |
| 18424 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18425 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ProcessNelHeaderHttps) { |
| 18426 | RequestPolicy(); |
| 18427 | ASSERT_EQ(1u, network_error_logging_service()->headers().size()); |
| 18428 | const auto& header = network_error_logging_service()->headers()[0]; |
| 18429 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 18430 | header.origin); |
| 18431 | EXPECT_EQ(IPAddress::IPv4Localhost(), header.received_ip_address); |
| 18432 | EXPECT_EQ("{\"report_to\": \"nel\", \"max_age\": 86400}", header.value); |
| 18433 | } |
| 18434 | |
| 18435 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18436 | DontProcessNelHeaderInvalidHttps) { |
| 18437 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18438 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18439 | RequestPolicy(cert_status); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18440 | histograms.ExpectBucketCount( |
| 18441 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18442 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, |
| 18443 | 1); |
| 18444 | } |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18445 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18446 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, CreateReportSuccess) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18447 | RequestPolicy(); |
| 18448 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18449 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 18450 | } |
| 18451 | |
| 18452 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18453 | CreateReportErrorAfterStart) { |
| 18454 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18455 | auto trans = |
| 18456 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18457 | |
| 18458 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
| 18459 | StaticSocketDataProvider data; |
| 18460 | data.set_connect_data(mock_connect); |
| 18461 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18462 | |
| 18463 | TestCompletionCallback callback; |
| 18464 | |
| 18465 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18466 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18467 | |
| 18468 | trans.reset(); |
| 18469 | |
| 18470 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18471 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18472 | IPAddress() /* server_ip */); |
| 18473 | } |
| 18474 | |
| 18475 | // Same as above except the error is ASYNC |
| 18476 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18477 | CreateReportErrorAfterStartAsync) { |
| 18478 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18479 | auto trans = |
| 18480 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18481 | |
| 18482 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
| 18483 | StaticSocketDataProvider data; |
| 18484 | data.set_connect_data(mock_connect); |
| 18485 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18486 | |
| 18487 | TestCompletionCallback callback; |
| 18488 | |
| 18489 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18490 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18491 | |
| 18492 | trans.reset(); |
| 18493 | |
| 18494 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18495 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18496 | IPAddress() /* server_ip */); |
| 18497 | } |
| 18498 | |
| 18499 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18500 | CreateReportReadBodyError) { |
| 18501 | std::string extra_header_string = extra_headers_.ToString(); |
| 18502 | MockRead data_reads[] = { |
| 18503 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18504 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18505 | MockRead("hello world"), |
| 18506 | MockRead(SYNCHRONOUS, OK), |
| 18507 | }; |
| 18508 | MockWrite data_writes[] = { |
| 18509 | MockWrite("GET / HTTP/1.1\r\n" |
| 18510 | "Host: www.example.org\r\n" |
| 18511 | "Connection: keep-alive\r\n"), |
| 18512 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18513 | }; |
| 18514 | |
| 18515 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18516 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18517 | |
| 18518 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18519 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18520 | |
| 18521 | // Log start time |
| 18522 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18523 | |
| 18524 | TestCompletionCallback callback; |
| 18525 | auto session = CreateSession(&session_deps_); |
| 18526 | auto trans = |
| 18527 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18528 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18529 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18530 | |
| 18531 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18532 | ASSERT_TRUE(response); |
| 18533 | |
| 18534 | EXPECT_TRUE(response->headers); |
| 18535 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 18536 | |
| 18537 | std::string response_data; |
| 18538 | rv = ReadTransaction(trans.get(), &response_data); |
| 18539 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 18540 | |
| 18541 | trans.reset(); |
| 18542 | |
| 18543 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18544 | |
| 18545 | CheckReport(0 /* index */, 200 /* status_code */, |
| 18546 | ERR_CONTENT_LENGTH_MISMATCH); |
| 18547 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18548 | network_error_logging_service()->errors()[0]; |
| 18549 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 18550 | } |
| 18551 | |
| 18552 | // Same as above except the final read is ASYNC. |
| 18553 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18554 | CreateReportReadBodyErrorAsync) { |
| 18555 | std::string extra_header_string = extra_headers_.ToString(); |
| 18556 | MockRead data_reads[] = { |
| 18557 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18558 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18559 | MockRead("hello world"), |
| 18560 | MockRead(ASYNC, OK), |
| 18561 | }; |
| 18562 | MockWrite data_writes[] = { |
| 18563 | MockWrite("GET / HTTP/1.1\r\n" |
| 18564 | "Host: www.example.org\r\n" |
| 18565 | "Connection: keep-alive\r\n"), |
| 18566 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18567 | }; |
| 18568 | |
| 18569 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18570 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18571 | |
| 18572 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18573 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18574 | |
| 18575 | // Log start time |
| 18576 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18577 | |
| 18578 | TestCompletionCallback callback; |
| 18579 | auto session = CreateSession(&session_deps_); |
| 18580 | auto trans = |
| 18581 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18582 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18583 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18584 | |
| 18585 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18586 | ASSERT_TRUE(response); |
| 18587 | |
| 18588 | EXPECT_TRUE(response->headers); |
| 18589 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 18590 | |
| 18591 | std::string response_data; |
| 18592 | rv = ReadTransaction(trans.get(), &response_data); |
| 18593 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 18594 | |
| 18595 | trans.reset(); |
| 18596 | |
| 18597 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18598 | |
| 18599 | CheckReport(0 /* index */, 200 /* status_code */, |
| 18600 | ERR_CONTENT_LENGTH_MISMATCH); |
| 18601 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18602 | network_error_logging_service()->errors()[0]; |
| 18603 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 18604 | } |
| 18605 | |
| 18606 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18607 | CreateReportRestartWithAuth) { |
| 18608 | std::string extra_header_string = extra_headers_.ToString(); |
| 18609 | static const base::TimeDelta kSleepDuration = |
| 18610 | base::TimeDelta::FromMilliseconds(10); |
| 18611 | |
| 18612 | MockWrite data_writes1[] = { |
| 18613 | MockWrite("GET / HTTP/1.1\r\n" |
| 18614 | "Host: www.example.org\r\n" |
| 18615 | "Connection: keep-alive\r\n"), |
| 18616 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18617 | }; |
| 18618 | |
| 18619 | MockRead data_reads1[] = { |
| 18620 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 18621 | // Give a couple authenticate options (only the middle one is actually |
| 18622 | // supported). |
| 18623 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 18624 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 18625 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 18626 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18627 | // Large content-length -- won't matter, as connection will be reset. |
| 18628 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 18629 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 18630 | }; |
| 18631 | |
| 18632 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18633 | // be issuing -- the final header line contains the credentials. |
| 18634 | MockWrite data_writes2[] = { |
| 18635 | MockWrite("GET / HTTP/1.1\r\n" |
| 18636 | "Host: www.example.org\r\n" |
| 18637 | "Connection: keep-alive\r\n" |
| 18638 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 18639 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18640 | }; |
| 18641 | |
| 18642 | // Lastly, the server responds with the actual content. |
| 18643 | MockRead data_reads2[] = { |
| 18644 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 18645 | MockRead("hello world"), |
| 18646 | MockRead(SYNCHRONOUS, OK), |
| 18647 | }; |
| 18648 | |
| 18649 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18650 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 18651 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18652 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18653 | |
| 18654 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18655 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18656 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18657 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18658 | |
| 18659 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18660 | base::TimeTicks restart_time; |
| 18661 | |
| 18662 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18663 | auto trans = |
| 18664 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18665 | |
| 18666 | TestCompletionCallback callback1; |
| 18667 | |
| 18668 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18669 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18670 | |
| 18671 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18672 | |
| 18673 | TestCompletionCallback callback2; |
| 18674 | |
| 18675 | // Wait 10 ms then restart with auth |
| 18676 | FastForwardBy(kSleepDuration); |
| 18677 | restart_time = base::TimeTicks::Now(); |
| 18678 | rv = |
| 18679 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 18680 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18681 | |
| 18682 | std::string response_data; |
| 18683 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 18684 | EXPECT_EQ("hello world", response_data); |
| 18685 | |
| 18686 | trans.reset(); |
| 18687 | |
| 18688 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 18689 | // retry. Note that we don't report the error draining the body, as the first |
| 18690 | // request already generated a report for the auth challenge. |
| 18691 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 18692 | |
| 18693 | // Check error report contents |
| 18694 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 18695 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 18696 | |
| 18697 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 18698 | network_error_logging_service()->errors()[0]; |
| 18699 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 18700 | network_error_logging_service()->errors()[1]; |
| 18701 | |
| 18702 | // Sanity-check elapsed time values |
| 18703 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 18704 | // Check that the start time is refreshed when restarting with auth. |
| 18705 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 18706 | } |
| 18707 | |
| 18708 | // Same as above, except draining the body before restarting fails |
| 18709 | // asynchronously. |
| 18710 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18711 | CreateReportRestartWithAuthAsync) { |
| 18712 | std::string extra_header_string = extra_headers_.ToString(); |
| 18713 | static const base::TimeDelta kSleepDuration = |
| 18714 | base::TimeDelta::FromMilliseconds(10); |
| 18715 | |
| 18716 | MockWrite data_writes1[] = { |
| 18717 | MockWrite("GET / HTTP/1.1\r\n" |
| 18718 | "Host: www.example.org\r\n" |
| 18719 | "Connection: keep-alive\r\n"), |
| 18720 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18721 | }; |
| 18722 | |
| 18723 | MockRead data_reads1[] = { |
| 18724 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 18725 | // Give a couple authenticate options (only the middle one is actually |
| 18726 | // supported). |
| 18727 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 18728 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 18729 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 18730 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18731 | // Large content-length -- won't matter, as connection will be reset. |
| 18732 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 18733 | MockRead(ASYNC, ERR_FAILED), |
| 18734 | }; |
| 18735 | |
| 18736 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18737 | // be issuing -- the final header line contains the credentials. |
| 18738 | MockWrite data_writes2[] = { |
| 18739 | MockWrite("GET / HTTP/1.1\r\n" |
| 18740 | "Host: www.example.org\r\n" |
| 18741 | "Connection: keep-alive\r\n" |
| 18742 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 18743 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18744 | }; |
| 18745 | |
| 18746 | // Lastly, the server responds with the actual content. |
| 18747 | MockRead data_reads2[] = { |
| 18748 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 18749 | MockRead("hello world"), |
| 18750 | MockRead(SYNCHRONOUS, OK), |
| 18751 | }; |
| 18752 | |
| 18753 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18754 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 18755 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18756 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18757 | |
| 18758 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18759 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18760 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18761 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18762 | |
| 18763 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18764 | base::TimeTicks restart_time; |
| 18765 | |
| 18766 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18767 | auto trans = |
| 18768 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18769 | |
| 18770 | TestCompletionCallback callback1; |
| 18771 | |
| 18772 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18773 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18774 | |
| 18775 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18776 | |
| 18777 | TestCompletionCallback callback2; |
| 18778 | |
| 18779 | // Wait 10 ms then restart with auth |
| 18780 | FastForwardBy(kSleepDuration); |
| 18781 | restart_time = base::TimeTicks::Now(); |
| 18782 | rv = |
| 18783 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 18784 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18785 | |
| 18786 | std::string response_data; |
| 18787 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 18788 | EXPECT_EQ("hello world", response_data); |
| 18789 | |
| 18790 | trans.reset(); |
| 18791 | |
| 18792 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 18793 | // retry. Note that we don't report the error draining the body, as the first |
| 18794 | // request already generated a report for the auth challenge. |
| 18795 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 18796 | |
| 18797 | // Check error report contents |
| 18798 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 18799 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 18800 | |
| 18801 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 18802 | network_error_logging_service()->errors()[0]; |
| 18803 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 18804 | network_error_logging_service()->errors()[1]; |
| 18805 | |
| 18806 | // Sanity-check elapsed time values |
| 18807 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 18808 | // Check that the start time is refreshed when restarting with auth. |
| 18809 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 18810 | } |
| 18811 | |
| 18812 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18813 | CreateReportRetryKeepAliveConnectionReset) { |
| 18814 | std::string extra_header_string = extra_headers_.ToString(); |
| 18815 | MockWrite data_writes1[] = { |
| 18816 | MockWrite("GET / HTTP/1.1\r\n" |
| 18817 | "Host: www.example.org\r\n" |
| 18818 | "Connection: keep-alive\r\n"), |
| 18819 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18820 | MockWrite("GET / HTTP/1.1\r\n" |
| 18821 | "Host: www.example.org\r\n" |
| 18822 | "Connection: keep-alive\r\n"), |
| 18823 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18824 | }; |
| 18825 | |
| 18826 | MockRead data_reads1[] = { |
| 18827 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 18828 | MockRead("hello"), |
| 18829 | // Connection is reset |
| 18830 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 18831 | }; |
| 18832 | |
| 18833 | // Successful retry |
| 18834 | MockRead data_reads2[] = { |
| 18835 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 18836 | MockRead("world"), |
| 18837 | MockRead(ASYNC, OK), |
| 18838 | }; |
| 18839 | |
| 18840 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18841 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 18842 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18843 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18844 | |
| 18845 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18846 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18847 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18848 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18849 | |
| 18850 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18851 | auto trans1 = |
| 18852 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18853 | |
| 18854 | TestCompletionCallback callback1; |
| 18855 | |
| 18856 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18857 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18858 | |
| 18859 | std::string response_data; |
| 18860 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 18861 | EXPECT_EQ("hello", response_data); |
| 18862 | |
| 18863 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18864 | |
| 18865 | auto trans2 = |
| 18866 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18867 | |
| 18868 | TestCompletionCallback callback2; |
| 18869 | |
| 18870 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 18871 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18872 | |
| 18873 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 18874 | EXPECT_EQ("world", response_data); |
| 18875 | |
| 18876 | trans1.reset(); |
| 18877 | trans2.reset(); |
| 18878 | |
| 18879 | // One OK report from first request, then a ERR_CONNECTION_RESET report from |
| 18880 | // the second request, then an OK report from the successful retry. |
| 18881 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 18882 | |
| 18883 | // Check error report contents |
| 18884 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 18885 | CheckReport(1 /* index */, 0 /* status_code */, ERR_CONNECTION_RESET); |
| 18886 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 18887 | } |
| 18888 | |
| 18889 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18890 | CreateReportRetryKeepAlive408) { |
| 18891 | std::string extra_header_string = extra_headers_.ToString(); |
| 18892 | MockWrite data_writes1[] = { |
| 18893 | MockWrite("GET / HTTP/1.1\r\n" |
| 18894 | "Host: www.example.org\r\n" |
| 18895 | "Connection: keep-alive\r\n"), |
| 18896 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18897 | MockWrite("GET / HTTP/1.1\r\n" |
| 18898 | "Host: www.example.org\r\n" |
| 18899 | "Connection: keep-alive\r\n"), |
| 18900 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18901 | }; |
| 18902 | |
| 18903 | MockRead data_reads1[] = { |
| 18904 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 18905 | MockRead("hello"), |
| 18906 | // 408 Request Timeout |
| 18907 | MockRead(SYNCHRONOUS, |
| 18908 | "HTTP/1.1 408 Request Timeout\r\n" |
| 18909 | "Connection: Keep-Alive\r\n" |
| 18910 | "Content-Length: 6\r\n\r\n" |
| 18911 | "Pickle"), |
| 18912 | }; |
| 18913 | |
| 18914 | // Successful retry |
| 18915 | MockRead data_reads2[] = { |
| 18916 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 18917 | MockRead("world"), |
| 18918 | MockRead(ASYNC, OK), |
| 18919 | }; |
| 18920 | |
| 18921 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18922 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 18923 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18924 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18925 | |
| 18926 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18927 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18928 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18929 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18930 | |
| 18931 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18932 | auto trans1 = |
| 18933 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18934 | |
| 18935 | TestCompletionCallback callback1; |
| 18936 | |
| 18937 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18938 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18939 | |
| 18940 | std::string response_data; |
| 18941 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 18942 | EXPECT_EQ("hello", response_data); |
| 18943 | |
| 18944 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18945 | |
| 18946 | auto trans2 = |
| 18947 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18948 | |
| 18949 | TestCompletionCallback callback2; |
| 18950 | |
| 18951 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 18952 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18953 | |
| 18954 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 18955 | EXPECT_EQ("world", response_data); |
| 18956 | |
| 18957 | trans1.reset(); |
| 18958 | trans2.reset(); |
| 18959 | |
| 18960 | // One 200 report from first request, then a 408 report from |
| 18961 | // the second request, then a 200 report from the successful retry. |
| 18962 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 18963 | |
| 18964 | // Check error report contents |
| 18965 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 18966 | CheckReport(1 /* index */, 408 /* status_code */, OK); |
| 18967 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 18968 | } |
| 18969 | |
| 18970 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18971 | CreateReportRetry421WithoutConnectionPooling) { |
| 18972 | // Two hosts resolve to the same IP address. |
| 18973 | const std::string ip_addr = "1.2.3.4"; |
| 18974 | IPAddress ip; |
| 18975 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 18976 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 18977 | |
| 18978 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
| 18979 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 18980 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 18981 | |
| 18982 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18983 | |
| 18984 | // Two requests on the first connection. |
| 18985 | spdy::SpdySerializedFrame req1( |
| 18986 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 18987 | spdy_util_.UpdateWithStreamDestruction(1); |
| 18988 | spdy::SpdySerializedFrame req2( |
| 18989 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 18990 | spdy::SpdySerializedFrame rst( |
| 18991 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
| 18992 | MockWrite writes1[] = { |
| 18993 | CreateMockWrite(req1, 0), |
| 18994 | CreateMockWrite(req2, 3), |
| 18995 | CreateMockWrite(rst, 6), |
| 18996 | }; |
| 18997 | |
| 18998 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 18999 | spdy::SpdySerializedFrame resp1( |
| 19000 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 19001 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 19002 | spdy::SpdyHeaderBlock response_headers; |
| 19003 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 19004 | spdy::SpdySerializedFrame resp2( |
| 19005 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 19006 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 19007 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 19008 | |
| 19009 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 19010 | SequencedSocketData data1(connect1, reads1, writes1); |
| 19011 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19012 | |
| 19013 | AddSSLSocketData(); |
| 19014 | |
| 19015 | // Retry the second request on a second connection. |
| 19016 | SpdyTestUtil spdy_util2; |
| 19017 | spdy::SpdySerializedFrame req3( |
| 19018 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 19019 | MockWrite writes2[] = { |
| 19020 | CreateMockWrite(req3, 0), |
| 19021 | }; |
| 19022 | |
| 19023 | spdy::SpdySerializedFrame resp3( |
| 19024 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 19025 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 19026 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 19027 | MockRead(ASYNC, 0, 3)}; |
| 19028 | |
| 19029 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 19030 | SequencedSocketData data2(connect2, reads2, writes2); |
| 19031 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19032 | |
| 19033 | AddSSLSocketData(); |
| 19034 | |
| 19035 | // Preload mail.example.org into HostCache. |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 19036 | int rv = session_deps_.host_resolver->LoadIntoCache( |
| 19037 | HostPortPair("mail.example.com", 443), base::nullopt); |
| 19038 | EXPECT_THAT(rv, IsOk()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19039 | |
| 19040 | HttpRequestInfo request1; |
| 19041 | request1.method = "GET"; |
| 19042 | request1.url = GURL("https://www.example.org/"); |
| 19043 | request1.load_flags = 0; |
| 19044 | request1.traffic_annotation = |
| 19045 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19046 | auto trans1 = |
| 19047 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19048 | |
Eric Orth | f4db66a | 2019-02-19 21:35:33 | [diff] [blame] | 19049 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19050 | rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 19051 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19052 | |
| 19053 | const HttpResponseInfo* response = trans1->GetResponseInfo(); |
| 19054 | ASSERT_TRUE(response); |
| 19055 | ASSERT_TRUE(response->headers); |
| 19056 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19057 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19058 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19059 | std::string response_data; |
| 19060 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19061 | EXPECT_EQ("hello!", response_data); |
| 19062 | |
| 19063 | trans1.reset(); |
| 19064 | |
| 19065 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19066 | |
| 19067 | HttpRequestInfo request2; |
| 19068 | request2.method = "GET"; |
| 19069 | request2.url = GURL("https://mail.example.org/"); |
| 19070 | request2.load_flags = 0; |
| 19071 | request2.traffic_annotation = |
| 19072 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19073 | auto trans2 = |
| 19074 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19075 | |
| 19076 | BoundTestNetLog log; |
| 19077 | rv = trans2->Start(&request2, callback.callback(), log.bound()); |
| 19078 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19079 | |
| 19080 | response = trans2->GetResponseInfo(); |
| 19081 | ASSERT_TRUE(response); |
| 19082 | ASSERT_TRUE(response->headers); |
| 19083 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19084 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19085 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19086 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19087 | EXPECT_EQ("hello!", response_data); |
| 19088 | |
| 19089 | trans2.reset(); |
| 19090 | |
| 19091 | // One 200 report from the first request, then a 421 report from the |
| 19092 | // second request, then a 200 report from the successful retry. |
| 19093 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19094 | |
| 19095 | // Check error report contents |
| 19096 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 19097 | network_error_logging_service()->errors()[0]; |
| 19098 | EXPECT_EQ(GURL("https://www.example.org/"), error1.uri); |
| 19099 | EXPECT_TRUE(error1.referrer.is_empty()); |
| 19100 | EXPECT_EQ("", error1.user_agent); |
| 19101 | EXPECT_EQ(ip, error1.server_ip); |
| 19102 | EXPECT_EQ("h2", error1.protocol); |
| 19103 | EXPECT_EQ("GET", error1.method); |
| 19104 | EXPECT_EQ(200, error1.status_code); |
| 19105 | EXPECT_EQ(OK, error1.type); |
| 19106 | EXPECT_EQ(0, error1.reporting_upload_depth); |
| 19107 | |
| 19108 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 19109 | network_error_logging_service()->errors()[1]; |
| 19110 | EXPECT_EQ(GURL("https://mail.example.org/"), error2.uri); |
| 19111 | EXPECT_TRUE(error2.referrer.is_empty()); |
| 19112 | EXPECT_EQ("", error2.user_agent); |
| 19113 | EXPECT_EQ(ip, error2.server_ip); |
| 19114 | EXPECT_EQ("h2", error2.protocol); |
| 19115 | EXPECT_EQ("GET", error2.method); |
| 19116 | EXPECT_EQ(421, error2.status_code); |
| 19117 | EXPECT_EQ(OK, error2.type); |
| 19118 | EXPECT_EQ(0, error2.reporting_upload_depth); |
| 19119 | |
| 19120 | const NetworkErrorLoggingService::RequestDetails& error3 = |
| 19121 | network_error_logging_service()->errors()[2]; |
| 19122 | EXPECT_EQ(GURL("https://mail.example.org/"), error3.uri); |
| 19123 | EXPECT_TRUE(error3.referrer.is_empty()); |
| 19124 | EXPECT_EQ("", error3.user_agent); |
| 19125 | EXPECT_EQ(ip, error3.server_ip); |
| 19126 | EXPECT_EQ("h2", error3.protocol); |
| 19127 | EXPECT_EQ("GET", error3.method); |
| 19128 | EXPECT_EQ(200, error3.status_code); |
| 19129 | EXPECT_EQ(OK, error3.type); |
| 19130 | EXPECT_EQ(0, error3.reporting_upload_depth); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19131 | } |
| 19132 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19133 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportHttp) { |
| 19134 | base::HistogramTester histograms; |
| 19135 | RequestPolicy(); |
| 19136 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19137 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19138 | |
| 19139 | // Make HTTP request |
| 19140 | std::string extra_header_string = extra_headers_.ToString(); |
| 19141 | MockRead data_reads[] = { |
| 19142 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 19143 | MockRead("hello world"), |
| 19144 | MockRead(SYNCHRONOUS, OK), |
| 19145 | }; |
| 19146 | MockWrite data_writes[] = { |
| 19147 | MockWrite("GET / HTTP/1.1\r\n" |
| 19148 | "Host: www.example.org\r\n" |
| 19149 | "Connection: keep-alive\r\n"), |
| 19150 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19151 | }; |
| 19152 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19153 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 19154 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 19155 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19156 | // Insecure url |
| 19157 | url_ = "http://www.example.org/"; |
| 19158 | request_.url = GURL(url_); |
| 19159 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19160 | TestCompletionCallback callback; |
| 19161 | auto session = CreateSession(&session_deps_); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19162 | auto trans = |
| 19163 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19164 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19165 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19166 | |
| 19167 | std::string response_data; |
| 19168 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19169 | EXPECT_EQ("hello world", response_data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19170 | |
| 19171 | // Insecure request does not generate a report |
| 19172 | histograms.ExpectBucketCount( |
| 19173 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
| 19174 | NetworkErrorLoggingService::RequestOutcome::DISCARDED_INSECURE_ORIGIN, 1); |
| 19175 | |
| 19176 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19177 | } |
| 19178 | |
| 19179 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19180 | DontCreateReportHttpError) { |
| 19181 | base::HistogramTester histograms; |
| 19182 | RequestPolicy(); |
| 19183 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19184 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19185 | |
| 19186 | // Make HTTP request that fails |
| 19187 | MockRead data_reads[] = { |
| 19188 | MockRead("hello world"), |
| 19189 | MockRead(SYNCHRONOUS, OK), |
| 19190 | }; |
| 19191 | |
| 19192 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
| 19193 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19194 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19195 | url_ = "http://www.originwithoutpolicy.com:2000/"; |
| 19196 | request_.url = GURL(url_); |
| 19197 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19198 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19199 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19200 | auto trans = |
| 19201 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19202 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19203 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19204 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 19205 | |
| 19206 | // Insecure request does not generate a report, regardless of existence of a |
| 19207 | // policy for the origin. |
| 19208 | histograms.ExpectBucketCount( |
| 19209 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
| 19210 | NetworkErrorLoggingService::RequestOutcome::DISCARDED_INSECURE_ORIGIN, 1); |
| 19211 | |
| 19212 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19213 | } |
| 19214 | |
Lily Chen | 90ae93cc | 2019-02-14 01:15:39 | [diff] [blame] | 19215 | // Don't report on proxy auth challenges, don't report if connecting through a |
| 19216 | // proxy. |
| 19217 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportProxy) { |
| 19218 | HttpRequestInfo request; |
| 19219 | request.method = "GET"; |
| 19220 | request.url = GURL("https://www.example.org/"); |
| 19221 | request.traffic_annotation = |
| 19222 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19223 | |
| 19224 | // Configure against proxy server "myproxy:70". |
| 19225 | session_deps_.proxy_resolution_service = |
| 19226 | ProxyResolutionService::CreateFixedFromPacResult( |
| 19227 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19228 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19229 | |
| 19230 | // Since we have proxy, should try to establish tunnel. |
| 19231 | MockWrite data_writes1[] = { |
| 19232 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19233 | "Host: www.example.org:443\r\n" |
| 19234 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 19235 | }; |
| 19236 | |
| 19237 | // The proxy responds to the connect with a 407, using a non-persistent |
| 19238 | // connection. |
| 19239 | MockRead data_reads1[] = { |
| 19240 | // No credentials. |
| 19241 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 19242 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 19243 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 19244 | }; |
| 19245 | |
| 19246 | MockWrite data_writes2[] = { |
| 19247 | // After calling trans->RestartWithAuth(), this is the request we should |
| 19248 | // be issuing -- the final header line contains the credentials. |
| 19249 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 19250 | "Host: www.example.org:443\r\n" |
| 19251 | "Proxy-Connection: keep-alive\r\n" |
| 19252 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 19253 | |
| 19254 | MockWrite("GET / HTTP/1.1\r\n" |
| 19255 | "Host: www.example.org\r\n" |
| 19256 | "Connection: keep-alive\r\n\r\n"), |
| 19257 | }; |
| 19258 | |
| 19259 | MockRead data_reads2[] = { |
| 19260 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 19261 | |
| 19262 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 19263 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 19264 | MockRead("Content-Length: 5\r\n\r\n"), |
| 19265 | MockRead(SYNCHRONOUS, "hello"), |
| 19266 | }; |
| 19267 | |
| 19268 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 19269 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 19270 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 19271 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 19272 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19273 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19274 | |
| 19275 | TestCompletionCallback callback1; |
| 19276 | |
| 19277 | auto trans = |
| 19278 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19279 | |
| 19280 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
| 19281 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 19282 | |
| 19283 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 19284 | EXPECT_EQ(407, response->headers->response_code()); |
| 19285 | |
| 19286 | std::string response_data; |
| 19287 | rv = ReadTransaction(trans.get(), &response_data); |
| 19288 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
| 19289 | |
| 19290 | // No NEL report is generated for the 407. |
| 19291 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 19292 | |
| 19293 | TestCompletionCallback callback2; |
| 19294 | |
| 19295 | rv = |
| 19296 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 19297 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 19298 | |
| 19299 | response = trans->GetResponseInfo(); |
| 19300 | EXPECT_EQ(200, response->headers->response_code()); |
| 19301 | |
| 19302 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19303 | EXPECT_EQ("hello", response_data); |
| 19304 | |
| 19305 | trans.reset(); |
| 19306 | |
| 19307 | // No NEL report is generated because we are behind a proxy. |
| 19308 | EXPECT_EQ(0u, network_error_logging_service()->errors().size()); |
| 19309 | } |
| 19310 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19311 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19312 | ReportContainsUploadDepth) { |
| 19313 | reporting_upload_depth_ = 7; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19314 | request_.reporting_upload_depth = reporting_upload_depth_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19315 | RequestPolicy(); |
| 19316 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19317 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19318 | network_error_logging_service()->errors()[0]; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19319 | EXPECT_EQ(7, error.reporting_upload_depth); |
| 19320 | } |
| 19321 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19322 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ReportElapsedTime) { |
| 19323 | std::string extra_header_string = extra_headers_.ToString(); |
| 19324 | static const base::TimeDelta kSleepDuration = |
| 19325 | base::TimeDelta::FromMilliseconds(10); |
| 19326 | |
| 19327 | std::vector<MockWrite> data_writes = { |
| 19328 | MockWrite(ASYNC, 0, |
| 19329 | "GET / HTTP/1.1\r\n" |
| 19330 | "Host: www.example.org\r\n" |
| 19331 | "Connection: keep-alive\r\n"), |
| 19332 | MockWrite(ASYNC, 1, extra_header_string.data()), |
| 19333 | }; |
| 19334 | |
| 19335 | std::vector<MockRead> data_reads = { |
| 19336 | // Write one byte of the status line, followed by a pause. |
| 19337 | MockRead(ASYNC, 2, "H"), |
| 19338 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 19339 | MockRead(ASYNC, 4, "TTP/1.1 200 OK\r\n\r\n"), |
| 19340 | MockRead(ASYNC, 5, "hello world"), |
| 19341 | MockRead(SYNCHRONOUS, OK, 6), |
| 19342 | }; |
| 19343 | |
| 19344 | SequencedSocketData data(data_reads, data_writes); |
| 19345 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19346 | |
| 19347 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19348 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19349 | |
| 19350 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19351 | |
| 19352 | auto trans = |
| 19353 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19354 | |
| 19355 | TestCompletionCallback callback; |
| 19356 | |
| 19357 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19358 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19359 | |
| 19360 | data.RunUntilPaused(); |
| 19361 | ASSERT_TRUE(data.IsPaused()); |
| 19362 | FastForwardBy(kSleepDuration); |
| 19363 | data.Resume(); |
| 19364 | |
| 19365 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19366 | |
| 19367 | std::string response_data; |
| 19368 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19369 | EXPECT_EQ("hello world", response_data); |
| 19370 | |
| 19371 | trans.reset(); |
| 19372 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19373 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19374 | |
| 19375 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19376 | |
| 19377 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19378 | network_error_logging_service()->errors()[0]; |
| 19379 | |
| 19380 | // Sanity-check elapsed time in error report |
| 19381 | EXPECT_EQ(kSleepDuration, error.elapsed_time); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19382 | } |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19383 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19384 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 19385 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 19386 | } // namespace net |