[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" |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 25 | #include "base/run_loop.h" |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 26 | #include "base/stl_util.h" |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 27 | #include "base/strings/string_piece.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 28 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 29 | #include "base/strings/utf_string_conversions.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 30 | #include "base/test/metrics/histogram_tester.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 31 | #include "base/test/simple_test_clock.h" |
| 32 | #include "base/test/simple_test_tick_clock.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 33 | #include "base/test/test_file_util.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 34 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 35 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 36 | #include "net/base/chunked_upload_data_stream.h" |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 37 | #include "net/base/completion_once_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 38 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 39 | #include "net/base/load_timing_info.h" |
| 40 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 41 | #include "net/base/net_errors.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 42 | #include "net/base/proxy_delegate.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 43 | #include "net/base/proxy_server.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 44 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 45 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 46 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 47 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 48 | #include "net/base/upload_file_element_reader.h" |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 49 | #include "net/cert/cert_status_flags.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 50 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 51 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 52 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 53 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 54 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 55 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 56 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 57 | #include "net/http/http_auth_scheme.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 58 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 59 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 60 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 61 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 62 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 63 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 64 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 65 | #include "net/http/http_stream_factory.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 66 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 67 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 68 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 69 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 70 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 71 | #include "net/log/test_net_log_entry.h" |
| 72 | #include "net/log/test_net_log_util.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 73 | #include "net/proxy_resolution/mock_proxy_resolver.h" |
| 74 | #include "net/proxy_resolution/proxy_config_service_fixed.h" |
| 75 | #include "net/proxy_resolution/proxy_info.h" |
Lily Houghton | ffe89daa0 | 2018-03-09 18:30:03 | [diff] [blame] | 76 | #include "net/proxy_resolution/proxy_resolution_service.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 77 | #include "net/proxy_resolution/proxy_resolver.h" |
| 78 | #include "net/proxy_resolution/proxy_resolver_factory.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 79 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 80 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 81 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 82 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 83 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 84 | #include "net/socket/next_proto.h" |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 85 | #include "net/socket/socket_tag.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 86 | #include "net/socket/socket_test_util.h" |
| 87 | #include "net/socket/ssl_client_socket.h" |
Bence Béky | 94658bf | 2018-05-11 19:22:58 | [diff] [blame] | 88 | #include "net/spdy/spdy_session.h" |
| 89 | #include "net/spdy/spdy_session_pool.h" |
| 90 | #include "net/spdy/spdy_test_util_common.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 91 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 92 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 93 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 94 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 95 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 96 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 97 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 98 | #include "net/test/test_data_directory.h" |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 99 | #include "net/test/test_with_scoped_task_environment.h" |
Victor Vasiliev | 27cc771 | 2019-01-24 11:50:14 | [diff] [blame] | 100 | #include "net/third_party/quiche/src/spdy/core/spdy_framer.h" |
[email protected] | baee31a | 2018-01-18 06:10:23 | [diff] [blame] | 101 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 102 | #include "net/websockets/websocket_handshake_stream_base.h" |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 103 | #include "net/websockets/websocket_test_util.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 104 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 105 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 106 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 107 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 108 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 109 | #if defined(NTLM_PORTABLE) |
| 110 | #include "base/base64.h" |
| 111 | #include "net/ntlm/ntlm_test_data.h" |
| 112 | #endif |
| 113 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 114 | #if BUILDFLAG(ENABLE_REPORTING) |
| 115 | #include "net/network_error_logging/network_error_logging_service.h" |
| 116 | #include "net/network_error_logging/network_error_logging_test_util.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 117 | #include "net/reporting/reporting_cache.h" |
| 118 | #include "net/reporting/reporting_client.h" |
| 119 | #include "net/reporting/reporting_header_parser.h" |
| 120 | #include "net/reporting/reporting_service.h" |
| 121 | #include "net/reporting/reporting_test_util.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 122 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 123 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 124 | using net::test::IsError; |
| 125 | using net::test::IsOk; |
| 126 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 127 | using base::ASCIIToUTF16; |
| 128 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 129 | //----------------------------------------------------------------------------- |
| 130 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 131 | namespace net { |
| 132 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 133 | namespace { |
| 134 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 135 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 136 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 137 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 138 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 139 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 140 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 141 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 142 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 143 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 144 | const base::string16 kSecond(ASCIIToUTF16("second")); |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 145 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 146 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 147 | const char kAlternativeServiceHttpHeader[] = |
| 148 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 149 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 150 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 151 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 152 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 153 | } |
| 154 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 155 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 156 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 157 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 158 | } |
| 159 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 160 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 161 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 162 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 163 | } |
| 164 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 165 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 166 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 167 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 168 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 169 | if (!params) |
| 170 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 171 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 172 | if (!params->GetList("headers", &header_list)) |
| 173 | return false; |
| 174 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 175 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 176 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 177 | return true; |
| 178 | } |
| 179 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 180 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 181 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 182 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 183 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 184 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 185 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 186 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 187 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 188 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 189 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 190 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 191 | |
| 192 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 193 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 194 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 195 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 196 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 197 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 198 | } |
| 199 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 200 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 201 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 202 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 203 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 204 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 205 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 206 | |
| 207 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 208 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 209 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 210 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 211 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 212 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 213 | load_timing_info.send_start); |
| 214 | |
| 215 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 216 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 217 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 218 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 219 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 220 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 224 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 225 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 226 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 227 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 228 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 229 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 230 | |
| 231 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 232 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 233 | load_timing_info.proxy_resolve_end); |
| 234 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 235 | load_timing_info.send_start); |
| 236 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 237 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 238 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 239 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 240 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 241 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 245 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 246 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 247 | int connect_timing_flags) { |
| 248 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 249 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 250 | |
| 251 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 252 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 253 | load_timing_info.proxy_resolve_end); |
| 254 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 255 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 256 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 257 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 258 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 259 | load_timing_info.send_start); |
| 260 | |
| 261 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 262 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 263 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 264 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 265 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 266 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 267 | } |
| 268 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 269 | // ProxyResolver that records URLs passed to it, and that can be told what |
| 270 | // result to return. |
| 271 | class CapturingProxyResolver : public ProxyResolver { |
| 272 | public: |
| 273 | CapturingProxyResolver() |
| 274 | : proxy_server_(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 80)) {} |
| 275 | ~CapturingProxyResolver() override = default; |
| 276 | |
| 277 | int GetProxyForURL(const GURL& url, |
| 278 | ProxyInfo* results, |
| 279 | CompletionOnceCallback callback, |
| 280 | std::unique_ptr<Request>* request, |
| 281 | const NetLogWithSource& net_log) override { |
| 282 | results->UseProxyServer(proxy_server_); |
| 283 | resolved_.push_back(url); |
| 284 | return OK; |
| 285 | } |
| 286 | |
| 287 | // Sets whether the resolver should use direct connections, instead of a |
| 288 | // proxy. |
| 289 | void set_proxy_server(ProxyServer proxy_server) { |
| 290 | proxy_server_ = proxy_server; |
| 291 | } |
| 292 | |
| 293 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 294 | |
| 295 | private: |
| 296 | std::vector<GURL> resolved_; |
| 297 | |
| 298 | ProxyServer proxy_server_; |
| 299 | |
| 300 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 301 | }; |
| 302 | |
| 303 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 304 | public: |
| 305 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 306 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 307 | |
| 308 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 309 | std::unique_ptr<ProxyResolver>* resolver, |
| 310 | CompletionOnceCallback callback, |
| 311 | std::unique_ptr<Request>* request) override { |
| 312 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
| 313 | return OK; |
| 314 | } |
| 315 | |
| 316 | private: |
| 317 | ProxyResolver* resolver_; |
| 318 | }; |
| 319 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 320 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 321 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 322 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 323 | } |
| 324 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 325 | class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 326 | public: |
| 327 | FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 328 | |
| 329 | // ProxyResolverFactory override. |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 330 | int CreateProxyResolver(const scoped_refptr<PacFileData>& script_data, |
| 331 | std::unique_ptr<ProxyResolver>* result, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 332 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 333 | std::unique_ptr<Request>* request) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 334 | return ERR_PAC_SCRIPT_FAILED; |
| 335 | } |
| 336 | }; |
| 337 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 338 | class TestSSLConfigService : public SSLConfigService { |
| 339 | public: |
| 340 | explicit TestSSLConfigService(const SSLConfig& config) : config_(config) {} |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 341 | ~TestSSLConfigService() override = default; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 342 | |
| 343 | void GetSSLConfig(SSLConfig* config) override { *config = config_; } |
| 344 | |
Nick Harper | 89bc721 | 2018-07-31 19:07:57 | [diff] [blame] | 345 | bool CanShareConnectionWithClientCerts( |
| 346 | const std::string& hostname) const override { |
| 347 | return false; |
| 348 | } |
| 349 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 350 | private: |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 351 | SSLConfig config_; |
| 352 | }; |
| 353 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 354 | } // namespace |
| 355 | |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 356 | class HttpNetworkTransactionTest : public PlatformTest, |
| 357 | public WithScopedTaskEnvironment { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 358 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 359 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 360 | // Important to restore the per-pool limit first, since the pool limit must |
| 361 | // always be greater than group limit, and the tests reduce both limits. |
| 362 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 363 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 364 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 365 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 366 | } |
| 367 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 368 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 369 | HttpNetworkTransactionTest() |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 370 | : WithScopedTaskEnvironment( |
| 371 | base::test::ScopedTaskEnvironment::MainThreadType::IO_MOCK_TIME, |
| 372 | base::test::ScopedTaskEnvironment::NowSource:: |
| 373 | MAIN_THREAD_MOCK_TIME), |
| 374 | ssl_(ASYNC, OK), |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 375 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 376 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 377 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 378 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 379 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 380 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 381 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 382 | struct SimpleGetHelperResult { |
| 383 | int rv; |
| 384 | std::string status_line; |
| 385 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 386 | int64_t total_received_bytes; |
| 387 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 388 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 389 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 390 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 391 | }; |
| 392 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 393 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 394 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 395 | base::RunLoop().RunUntilIdle(); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 396 | // Set an initial delay to ensure that the first call to TimeTicks::Now() |
| 397 | // before incrementing the counter does not return a null value. |
| 398 | FastForwardBy(TimeDelta::FromSeconds(1)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 399 | } |
| 400 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 401 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 402 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 403 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 404 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 405 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 406 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 407 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 408 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 409 | } |
| 410 | |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 411 | void Check100ResponseTiming(bool use_spdy); |
| 412 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 413 | // Either |write_failure| specifies a write failure or |read_failure| |
| 414 | // specifies a read failure when using a reused socket. In either case, the |
| 415 | // failure should cause the network transaction to resend the request, and the |
| 416 | // other argument should be NULL. |
| 417 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 418 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 419 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 420 | // Either |write_failure| specifies a write failure or |read_failure| |
| 421 | // specifies a read failure when using a reused socket. In either case, the |
| 422 | // failure should cause the network transaction to resend the request, and the |
| 423 | // other argument should be NULL. |
| 424 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 425 | const MockRead* read_failure, |
| 426 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 427 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 428 | SimpleGetHelperResult SimpleGetHelperForData( |
| 429 | base::span<StaticSocketDataProvider*> providers) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 430 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 431 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 432 | HttpRequestInfo request; |
| 433 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 434 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 435 | request.traffic_annotation = |
| 436 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 437 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 438 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 439 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 440 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 441 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 442 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 443 | for (auto* provider : providers) { |
| 444 | session_deps_.socket_factory->AddSocketDataProvider(provider); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 445 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 446 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 447 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 448 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 449 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 450 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 451 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 452 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 453 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 454 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 455 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 456 | |
| 457 | // Even in the failure cases that use this function, connections are always |
| 458 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 459 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 460 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 461 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 462 | if (out.rv != OK) |
| 463 | return out; |
| 464 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 465 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 466 | // Can't use ASSERT_* inside helper functions like this, so |
| 467 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 468 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 469 | out.rv = ERR_UNEXPECTED; |
| 470 | return out; |
| 471 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 472 | out.status_line = response->headers->GetStatusLine(); |
| 473 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 474 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 475 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 476 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 477 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 478 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 479 | EXPECT_EQ(got_endpoint, |
| 480 | out.remote_endpoint_after_start.address().size() > 0); |
| 481 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 482 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 483 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 484 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 485 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 486 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 487 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 488 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 489 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 490 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 491 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 492 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 493 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 494 | std::string line; |
| 495 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 496 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 497 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 498 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 499 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 500 | std::string value; |
| 501 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 502 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 503 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 504 | EXPECT_EQ("keep-alive", value); |
| 505 | |
| 506 | std::string response_headers; |
| 507 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 508 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 509 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 510 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 511 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 512 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 513 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 514 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 515 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 516 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 517 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 518 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 519 | SimpleGetHelperResult SimpleGetHelper(base::span<const MockRead> data_reads) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 520 | MockWrite data_writes[] = { |
| 521 | MockWrite("GET / HTTP/1.1\r\n" |
| 522 | "Host: www.example.org\r\n" |
| 523 | "Connection: keep-alive\r\n\r\n"), |
| 524 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 525 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 526 | StaticSocketDataProvider reads(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 527 | StaticSocketDataProvider* data[] = {&reads}; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 528 | SimpleGetHelperResult out = SimpleGetHelperForData(data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 529 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 530 | EXPECT_EQ(CountWriteBytes(data_writes), out.total_sent_bytes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 531 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 532 | } |
| 533 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 534 | void AddSSLSocketData() { |
| 535 | ssl_.next_proto = kProtoHTTP2; |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 536 | ssl_.ssl_info.cert = |
| 537 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 538 | ASSERT_TRUE(ssl_.ssl_info.cert); |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 539 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 540 | } |
| 541 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 542 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 543 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 544 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 545 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 546 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 547 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 548 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 549 | // These clocks are defined here, even though they're only used in the |
| 550 | // Reporting tests below, since they need to be destroyed after |
| 551 | // |session_deps_|. |
| 552 | base::SimpleTestClock clock_; |
| 553 | base::SimpleTestTickClock tick_clock_; |
| 554 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 555 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 556 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 557 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 558 | |
| 559 | // Original socket limits. Some tests set these. Safest to always restore |
| 560 | // them once each test has been run. |
| 561 | int old_max_group_sockets_; |
| 562 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 563 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 564 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 565 | namespace { |
| 566 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 567 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 568 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 569 | BeforeHeadersSentHandler() |
| 570 | : observed_before_headers_sent_with_proxy_(false), |
| 571 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 572 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 573 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 574 | HttpRequestHeaders* request_headers) { |
| 575 | observed_before_headers_sent_ = true; |
| 576 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 577 | !proxy_info.is_quic()) { |
| 578 | return; |
| 579 | } |
| 580 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 581 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 582 | } |
| 583 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 584 | bool observed_before_headers_sent_with_proxy() const { |
| 585 | return observed_before_headers_sent_with_proxy_; |
| 586 | } |
| 587 | |
| 588 | bool observed_before_headers_sent() const { |
| 589 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | std::string observed_proxy_server_uri() const { |
| 593 | return observed_proxy_server_uri_; |
| 594 | } |
| 595 | |
| 596 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 597 | bool observed_before_headers_sent_with_proxy_; |
| 598 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 599 | std::string observed_proxy_server_uri_; |
| 600 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 601 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 602 | }; |
| 603 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 604 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 605 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 606 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 607 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 608 | const int sizeof_row = strlen(row); |
| 609 | const int num_rows = static_cast<int>( |
| 610 | ceil(static_cast<float>(size) / sizeof_row)); |
| 611 | const int sizeof_data = num_rows * sizeof_row; |
| 612 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 613 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 614 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 615 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 616 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 617 | } |
| 618 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 619 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 620 | uint64_t MockGetMSTime() { |
| 621 | // Tue, 23 May 2017 20:13:07 +0000 |
| 622 | return 131400439870000000; |
| 623 | } |
| 624 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 625 | // Alternative functions that eliminate randomness and dependency on the local |
| 626 | // host name so that the generated NTLM messages are reproducible. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 627 | void MockGenerateRandom(uint8_t* output, size_t n) { |
| 628 | // This is set to 0xaa because the client challenge for testing in |
| 629 | // [MS-NLMP] Section 4.2.1 is 8 bytes of 0xaa. |
| 630 | memset(output, 0xaa, n); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 631 | } |
| 632 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 633 | std::string MockGetHostName() { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 634 | return ntlm::test::kHostnameAscii; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 635 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 636 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 637 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 638 | template<typename ParentPool> |
| 639 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 640 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 641 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 642 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 643 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 644 | const std::string last_group_name_received() const { |
| 645 | return last_group_name_; |
| 646 | } |
| 647 | |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 648 | bool socket_requested() const { return socket_requested_; } |
| 649 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 650 | int RequestSocket(const std::string& group_name, |
| 651 | const void* socket_params, |
| 652 | RequestPriority priority, |
Paul Jensen | 8d6f87ec | 2018-01-13 00:46:54 | [diff] [blame] | 653 | const SocketTag& socket_tag, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 654 | ClientSocketPool::RespectLimits respect_limits, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 655 | ClientSocketHandle* handle, |
Bence Béky | 5a8662b | 2018-07-03 13:04:03 | [diff] [blame] | 656 | CompletionOnceCallback callback, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 657 | const NetLogWithSource& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 658 | last_group_name_ = group_name; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 659 | socket_requested_ = true; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 660 | return ERR_IO_PENDING; |
| 661 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 662 | void CancelRequest(const std::string& group_name, |
| 663 | ClientSocketHandle* handle) override {} |
| 664 | void ReleaseSocket(const std::string& group_name, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 665 | std::unique_ptr<StreamSocket> socket, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 666 | int id) override {} |
| 667 | void CloseIdleSockets() override {} |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 668 | void CloseIdleSocketsInGroup(const std::string& group_name) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 669 | int IdleSocketCount() const override { return 0; } |
| 670 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 671 | return 0; |
| 672 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 673 | LoadState GetLoadState(const std::string& group_name, |
| 674 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 675 | return LOAD_STATE_IDLE; |
| 676 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 677 | |
| 678 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 679 | std::string last_group_name_; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 680 | bool socket_requested_ = false; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 681 | }; |
| 682 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 683 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 684 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 685 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 686 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 687 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 688 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 689 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 690 | CaptureGroupNameSSLSocketPool; |
| 691 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 692 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 693 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 694 | HostResolver* host_resolver, |
| 695 | CertVerifier* /* cert_verifier */) |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 696 | : ParentPool(0, 0, host_resolver, NULL, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 697 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 698 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 699 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 700 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 701 | CertVerifier* /* cert_verifier */) |
Wojciech Dzierżanowski | 1f82356 | 2019-01-18 11:26:00 | [diff] [blame] | 702 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL, NULL, NULL) {} |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 703 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 704 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 705 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 706 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 707 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 708 | : SSLClientSocketPool(0, |
| 709 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 710 | cert_verifier, |
| 711 | NULL, |
| 712 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 713 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 714 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 715 | std::string(), |
| 716 | NULL, |
| 717 | NULL, |
| 718 | NULL, |
| 719 | NULL, |
| 720 | NULL, |
Matt Menke | c621aead0 | 2019-01-10 02:06:15 | [diff] [blame] | 721 | NULL, |
| 722 | NULL) {} |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 723 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 724 | //----------------------------------------------------------------------------- |
| 725 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 726 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 727 | // configured for common cases. |
| 728 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 729 | if (!auth_challenge) |
| 730 | return false; |
| 731 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 732 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 733 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 734 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 735 | return true; |
| 736 | } |
| 737 | |
| 738 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 739 | if (!auth_challenge) |
| 740 | return false; |
| 741 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 742 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 743 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 744 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 745 | return true; |
| 746 | } |
| 747 | |
| 748 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 749 | if (!auth_challenge) |
| 750 | return false; |
| 751 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 752 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 753 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 754 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 755 | return true; |
| 756 | } |
| 757 | |
| 758 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 759 | if (!auth_challenge) |
| 760 | return false; |
| 761 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 762 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 763 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 764 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 765 | return true; |
| 766 | } |
| 767 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 768 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 769 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 770 | if (!auth_challenge) |
| 771 | return false; |
| 772 | EXPECT_FALSE(auth_challenge->is_proxy); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 773 | EXPECT_EQ("https://server", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 774 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 775 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 776 | return true; |
| 777 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 778 | |
| 779 | bool CheckNTLMProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 780 | if (!auth_challenge) |
| 781 | return false; |
| 782 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 783 | EXPECT_EQ("http://server", auth_challenge->challenger.Serialize()); |
| 784 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 785 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
| 786 | return true; |
| 787 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 788 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 789 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 790 | } // namespace |
| 791 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 792 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 793 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 794 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 795 | } |
| 796 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 797 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 798 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 799 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 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); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 804 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 805 | EXPECT_EQ("HTTP/1.0 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); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 808 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 809 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 810 | |
| 811 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 815 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 816 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 817 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 818 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 819 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 820 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 821 | EXPECT_THAT(out.rv, IsOk()); |
| 822 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 823 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 824 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 825 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 826 | } |
| 827 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 828 | // Response with no status line, and a weird port. Should fail by default. |
| 829 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 830 | MockRead data_reads[] = { |
| 831 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 832 | }; |
| 833 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 834 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 835 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 836 | |
| 837 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 838 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 839 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 840 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 841 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 842 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 843 | request.method = "GET"; |
| 844 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 845 | request.traffic_annotation = |
| 846 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 847 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 848 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 849 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 850 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 851 | } |
| 852 | |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 853 | // Tests that request info can be destroyed after the headers phase is complete. |
| 854 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoReadDestroyRequestInfo) { |
| 855 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 856 | auto trans = |
| 857 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 858 | |
| 859 | MockRead data_reads[] = { |
| 860 | MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Connection: keep-alive\r\n"), |
| 861 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, 0), |
| 862 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 863 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 864 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 865 | |
| 866 | TestCompletionCallback callback; |
| 867 | |
| 868 | { |
| 869 | auto request = std::make_unique<HttpRequestInfo>(); |
| 870 | request->method = "GET"; |
| 871 | request->url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 872 | request->traffic_annotation = |
| 873 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 874 | |
| 875 | int rv = |
| 876 | trans->Start(request.get(), callback.callback(), NetLogWithSource()); |
| 877 | |
| 878 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 879 | } // Let request info be destroyed. |
| 880 | |
| 881 | trans.reset(); |
| 882 | } |
| 883 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 884 | // Response with no status line, and a weird port. Option to allow weird ports |
| 885 | // enabled. |
| 886 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 887 | MockRead data_reads[] = { |
| 888 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 889 | }; |
| 890 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 891 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 892 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 893 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 894 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 895 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 896 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 897 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 898 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 899 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 900 | request.method = "GET"; |
| 901 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 902 | request.traffic_annotation = |
| 903 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 904 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 905 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 906 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 907 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 908 | |
| 909 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 910 | ASSERT_TRUE(info->headers); |
| 911 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 912 | |
| 913 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 914 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 915 | } |
| 916 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 917 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 918 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 919 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 920 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 921 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 922 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 923 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 924 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 925 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 926 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 927 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 928 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 932 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 933 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 934 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 935 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 936 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 937 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 938 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 939 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 940 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 941 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 942 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 946 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 947 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 948 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 949 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 950 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 951 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 952 | EXPECT_THAT(out.rv, IsOk()); |
| 953 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 954 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 955 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 956 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 960 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 961 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 962 | MockRead("\n"), |
| 963 | MockRead("\n"), |
| 964 | MockRead("Q"), |
| 965 | MockRead("J"), |
| 966 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 967 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 968 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 969 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 970 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 971 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 972 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 973 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 974 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 975 | } |
| 976 | |
| 977 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 978 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 979 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 980 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 981 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 982 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 983 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 984 | EXPECT_THAT(out.rv, IsOk()); |
| 985 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 986 | EXPECT_EQ("HTT", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 987 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 988 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 989 | } |
| 990 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 991 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 992 | // persistent connection. The response should still terminate since a 204 |
| 993 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 994 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 995 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 996 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 997 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 998 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 999 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1000 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1001 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1002 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1003 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 1004 | EXPECT_EQ("", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1005 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1006 | int64_t response_size = reads_size - strlen(junk); |
| 1007 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 1008 | } |
| 1009 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1010 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1011 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1012 | std::string final_chunk = "0\r\n\r\n"; |
| 1013 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 1014 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1015 | MockRead data_reads[] = { |
| 1016 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 1017 | MockRead("5\r\nHello\r\n"), |
| 1018 | MockRead("1\r\n"), |
| 1019 | MockRead(" \r\n"), |
| 1020 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 1021 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1022 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1023 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1024 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1025 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1026 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1027 | EXPECT_EQ("Hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1028 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 1029 | int64_t response_size = reads_size - extra_data.size(); |
| 1030 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1031 | } |
| 1032 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1033 | // Next tests deal with http://crbug.com/56344. |
| 1034 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1035 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1036 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 1037 | MockRead data_reads[] = { |
| 1038 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1039 | MockRead("Content-Length: 10\r\n"), |
| 1040 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1041 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1042 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1043 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1044 | } |
| 1045 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1046 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1047 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 1048 | MockRead data_reads[] = { |
| 1049 | MockRead("HTTP/1.1 200 OK\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 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1060 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1061 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1062 | // More than 2 dupes. |
| 1063 | { |
| 1064 | MockRead data_reads[] = { |
| 1065 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1066 | MockRead("Content-Length: 5\r\n"), |
| 1067 | MockRead("Content-Length: 5\r\n"), |
| 1068 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1069 | MockRead("Hello"), |
| 1070 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1071 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1072 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1073 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1074 | EXPECT_EQ("Hello", out.response_data); |
| 1075 | } |
| 1076 | // HTTP/1.0 |
| 1077 | { |
| 1078 | MockRead data_reads[] = { |
| 1079 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1080 | MockRead("Content-Length: 5\r\n"), |
| 1081 | MockRead("Content-Length: 5\r\n"), |
| 1082 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1083 | MockRead("Hello"), |
| 1084 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1085 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1086 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1087 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1088 | EXPECT_EQ("Hello", out.response_data); |
| 1089 | } |
| 1090 | // 2 dupes and one mismatched. |
| 1091 | { |
| 1092 | MockRead data_reads[] = { |
| 1093 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1094 | MockRead("Content-Length: 10\r\n"), |
| 1095 | MockRead("Content-Length: 10\r\n"), |
| 1096 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1097 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1098 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1099 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1100 | } |
| 1101 | } |
| 1102 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1103 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1104 | MultipleContentLengthHeadersTransferEncoding) { |
| 1105 | MockRead data_reads[] = { |
| 1106 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1107 | MockRead("Content-Length: 666\r\n"), |
| 1108 | MockRead("Content-Length: 1337\r\n"), |
| 1109 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1110 | MockRead("5\r\nHello\r\n"), |
| 1111 | MockRead("1\r\n"), |
| 1112 | MockRead(" \r\n"), |
| 1113 | MockRead("5\r\nworld\r\n"), |
| 1114 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1115 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1116 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1117 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1118 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1119 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1120 | EXPECT_EQ("Hello world", out.response_data); |
| 1121 | } |
| 1122 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1123 | // Next tests deal with http://crbug.com/98895. |
| 1124 | |
| 1125 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1126 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1127 | MockRead data_reads[] = { |
| 1128 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1129 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1130 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1131 | MockRead("Hello"), |
| 1132 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1133 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1134 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1135 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1136 | EXPECT_EQ("Hello", out.response_data); |
| 1137 | } |
| 1138 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1139 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1140 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1141 | MockRead data_reads[] = { |
| 1142 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1143 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1144 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1145 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1146 | MockRead("Hello"), |
| 1147 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1148 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1149 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1150 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1151 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1152 | } |
| 1153 | |
| 1154 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1155 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1156 | MockRead data_reads[] = { |
| 1157 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1158 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1159 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1160 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1161 | MockRead("Hello"), |
| 1162 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1163 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1164 | EXPECT_THAT(out.rv, |
| 1165 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1166 | } |
| 1167 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1168 | // Checks that two identical Location headers result in no error. |
| 1169 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1170 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1171 | MockRead data_reads[] = { |
| 1172 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1173 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1174 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1175 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1176 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1177 | }; |
| 1178 | |
| 1179 | HttpRequestInfo request; |
| 1180 | request.method = "GET"; |
| 1181 | request.url = GURL("http://redirect.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1182 | request.traffic_annotation = |
| 1183 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1184 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1185 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1186 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1187 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1188 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1189 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1190 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1191 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1192 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1193 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1194 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1195 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1196 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1197 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1198 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1199 | ASSERT_TRUE(response); |
| 1200 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1201 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1202 | std::string url; |
| 1203 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1204 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1205 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1206 | } |
| 1207 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1208 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1209 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1210 | MockRead data_reads[] = { |
| 1211 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1212 | MockRead("Location: http://good.com/\r\n"), |
| 1213 | MockRead("Location: http://evil.com/\r\n"), |
| 1214 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1215 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1216 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1217 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1218 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1219 | } |
| 1220 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1221 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1222 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1223 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1224 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1225 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1226 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1227 | request.traffic_annotation = |
| 1228 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1229 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1230 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1231 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1232 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1233 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1234 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1235 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1236 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1237 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1238 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1239 | "Host: www.example.org\r\n" |
| 1240 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1241 | }; |
| 1242 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1243 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1244 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1245 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1246 | // No response body because the test stops reading here. |
| 1247 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1248 | }; |
| 1249 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1250 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1251 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1252 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1253 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1254 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1255 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1256 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1257 | |
| 1258 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1259 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1260 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1261 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1262 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1263 | |
| 1264 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1265 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1266 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1267 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1268 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1269 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1270 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1271 | |
| 1272 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1273 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1274 | bool has_server_header = response->headers->EnumerateHeader( |
| 1275 | &iter, "Server", &server_header); |
| 1276 | EXPECT_TRUE(has_server_header); |
| 1277 | EXPECT_EQ("Blah", server_header); |
| 1278 | |
| 1279 | // Reading should give EOF right away, since there is no message body |
| 1280 | // (despite non-zero content-length). |
| 1281 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1282 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1283 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1284 | EXPECT_EQ("", response_data); |
| 1285 | } |
| 1286 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1287 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1288 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1289 | |
| 1290 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1291 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1292 | MockRead("hello"), |
| 1293 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1294 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1295 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1296 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1297 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1298 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1299 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1300 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1301 | "hello", "world" |
| 1302 | }; |
| 1303 | |
| 1304 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1305 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1306 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1307 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1308 | request.traffic_annotation = |
| 1309 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1310 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1311 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1312 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1313 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1314 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1315 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1316 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1317 | |
| 1318 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1319 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1320 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1321 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1322 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1323 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1324 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1325 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1326 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1327 | |
| 1328 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1329 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1330 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1331 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1332 | } |
| 1333 | } |
| 1334 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1335 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1336 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1337 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1338 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1339 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1340 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1341 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1342 | request.method = "POST"; |
| 1343 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1344 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1345 | request.traffic_annotation = |
| 1346 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1347 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1348 | // Check the upload progress returned before initialization is correct. |
| 1349 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1350 | EXPECT_EQ(0u, progress.size()); |
| 1351 | EXPECT_EQ(0u, progress.position()); |
| 1352 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1353 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1354 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1355 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1356 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1357 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1358 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1359 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1360 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1361 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1362 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1363 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1364 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1365 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1366 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1367 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1368 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1369 | |
| 1370 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1371 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1372 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1373 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1374 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1375 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1376 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1377 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1378 | |
| 1379 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1380 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1381 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1382 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1383 | } |
| 1384 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1385 | // This test is almost the same as Ignores100 above, but the response contains |
| 1386 | // 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] | 1387 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1388 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1389 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1390 | request.method = "GET"; |
| 1391 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1392 | request.traffic_annotation = |
| 1393 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1394 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1395 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1396 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1397 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1398 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1399 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1400 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1401 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1402 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1403 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1404 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1405 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1406 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1407 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1408 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1409 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1410 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1411 | |
| 1412 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1413 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1414 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1415 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1416 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1417 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1418 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1419 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1420 | |
| 1421 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1422 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1423 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1424 | EXPECT_EQ("hello world", response_data); |
| 1425 | } |
| 1426 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1427 | TEST_F(HttpNetworkTransactionTest, LoadTimingMeasuresTimeToFirstByteForHttp) { |
| 1428 | static const base::TimeDelta kDelayAfterFirstByte = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1429 | base::TimeDelta::FromMilliseconds(10); |
| 1430 | |
| 1431 | HttpRequestInfo request; |
| 1432 | request.method = "GET"; |
| 1433 | request.url = GURL("http://www.foo.com/"); |
| 1434 | request.traffic_annotation = |
| 1435 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1436 | |
| 1437 | std::vector<MockWrite> data_writes = { |
| 1438 | MockWrite(ASYNC, 0, |
| 1439 | "GET / HTTP/1.1\r\n" |
| 1440 | "Host: www.foo.com\r\n" |
| 1441 | "Connection: keep-alive\r\n\r\n"), |
| 1442 | }; |
| 1443 | |
| 1444 | std::vector<MockRead> data_reads = { |
| 1445 | // Write one byte of the status line, followed by a pause. |
| 1446 | MockRead(ASYNC, 1, "H"), |
| 1447 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1448 | MockRead(ASYNC, 3, "TTP/1.1 200 OK\r\n\r\n"), |
| 1449 | MockRead(ASYNC, 4, "hello world"), |
| 1450 | MockRead(SYNCHRONOUS, OK, 5), |
| 1451 | }; |
| 1452 | |
| 1453 | SequencedSocketData data(data_reads, data_writes); |
| 1454 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1455 | |
| 1456 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1457 | |
| 1458 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1459 | |
| 1460 | TestCompletionCallback callback; |
| 1461 | |
| 1462 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1463 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1464 | |
| 1465 | data.RunUntilPaused(); |
| 1466 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1467 | FastForwardBy(kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1468 | data.Resume(); |
| 1469 | |
| 1470 | rv = callback.WaitForResult(); |
| 1471 | EXPECT_THAT(rv, IsOk()); |
| 1472 | |
| 1473 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1474 | ASSERT_TRUE(response); |
| 1475 | |
| 1476 | EXPECT_TRUE(response->headers); |
| 1477 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1478 | |
| 1479 | LoadTimingInfo load_timing_info; |
| 1480 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1481 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1482 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1483 | // Ensure we didn't include the delay in the TTFB time. |
| 1484 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1485 | load_timing_info.connect_timing.connect_end); |
| 1486 | // Ensure that the mock clock advanced at all. |
| 1487 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1488 | kDelayAfterFirstByte); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1489 | |
| 1490 | std::string response_data; |
| 1491 | rv = ReadTransaction(&trans, &response_data); |
| 1492 | EXPECT_THAT(rv, IsOk()); |
| 1493 | EXPECT_EQ("hello world", response_data); |
| 1494 | } |
| 1495 | |
| 1496 | // Tests that the time-to-first-byte reported in a transaction's load timing |
| 1497 | // info uses the first response, even if 1XX/informational. |
| 1498 | void HttpNetworkTransactionTest::Check100ResponseTiming(bool use_spdy) { |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1499 | static const base::TimeDelta kDelayAfter100Response = |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1500 | base::TimeDelta::FromMilliseconds(10); |
| 1501 | |
| 1502 | HttpRequestInfo request; |
| 1503 | request.method = "GET"; |
| 1504 | request.url = GURL("https://www.foo.com/"); |
| 1505 | request.traffic_annotation = |
| 1506 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 1507 | |
| 1508 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 1509 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 1510 | |
| 1511 | std::vector<MockWrite> data_writes; |
| 1512 | std::vector<MockRead> data_reads; |
| 1513 | |
| 1514 | spdy::SpdySerializedFrame spdy_req( |
| 1515 | spdy_util_.ConstructSpdyGet(request.url.spec().c_str(), 1, LOWEST)); |
| 1516 | |
| 1517 | spdy::SpdyHeaderBlock spdy_resp1_headers; |
| 1518 | spdy_resp1_headers[spdy::kHttp2StatusHeader] = "100"; |
| 1519 | spdy::SpdySerializedFrame spdy_resp1( |
| 1520 | spdy_util_.ConstructSpdyReply(1, spdy_resp1_headers.Clone())); |
| 1521 | spdy::SpdySerializedFrame spdy_resp2( |
| 1522 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 1523 | spdy::SpdySerializedFrame spdy_data( |
| 1524 | spdy_util_.ConstructSpdyDataFrame(1, "hello world", true)); |
| 1525 | |
| 1526 | if (use_spdy) { |
| 1527 | ssl.next_proto = kProtoHTTP2; |
| 1528 | |
| 1529 | data_writes = {CreateMockWrite(spdy_req, 0)}; |
| 1530 | |
| 1531 | data_reads = { |
| 1532 | CreateMockRead(spdy_resp1, 1), MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1533 | CreateMockRead(spdy_resp2, 3), CreateMockRead(spdy_data, 4), |
| 1534 | MockRead(SYNCHRONOUS, OK, 5), |
| 1535 | }; |
| 1536 | } else { |
| 1537 | data_writes = { |
| 1538 | MockWrite(ASYNC, 0, |
| 1539 | "GET / HTTP/1.1\r\n" |
| 1540 | "Host: www.foo.com\r\n" |
| 1541 | "Connection: keep-alive\r\n\r\n"), |
| 1542 | }; |
| 1543 | |
| 1544 | data_reads = { |
| 1545 | MockRead(ASYNC, 1, "HTTP/1.1 100 Continue\r\n\r\n"), |
| 1546 | MockRead(ASYNC, ERR_IO_PENDING, 2), |
| 1547 | |
| 1548 | MockRead(ASYNC, 3, "HTTP/1.1 200 OK\r\n\r\n"), |
| 1549 | MockRead(ASYNC, 4, "hello world"), |
| 1550 | MockRead(SYNCHRONOUS, OK, 5), |
| 1551 | }; |
| 1552 | } |
| 1553 | |
| 1554 | SequencedSocketData data(data_reads, data_writes); |
| 1555 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 1556 | |
| 1557 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1558 | |
| 1559 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1560 | |
| 1561 | TestCompletionCallback callback; |
| 1562 | |
| 1563 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1564 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1565 | |
| 1566 | data.RunUntilPaused(); |
| 1567 | // We should now have parsed the 100 response and hit ERR_IO_PENDING. Insert |
| 1568 | // the delay before parsing the 200 response. |
| 1569 | ASSERT_TRUE(data.IsPaused()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1570 | FastForwardBy(kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1571 | data.Resume(); |
| 1572 | |
| 1573 | rv = callback.WaitForResult(); |
| 1574 | EXPECT_THAT(rv, IsOk()); |
| 1575 | |
| 1576 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 1577 | ASSERT_TRUE(response); |
| 1578 | |
| 1579 | LoadTimingInfo load_timing_info; |
| 1580 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
| 1581 | EXPECT_FALSE(load_timing_info.receive_headers_start.is_null()); |
| 1582 | EXPECT_FALSE(load_timing_info.connect_timing.connect_end.is_null()); |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1583 | // Ensure we didn't include the delay in the TTFB time. |
| 1584 | EXPECT_EQ(load_timing_info.receive_headers_start, |
| 1585 | load_timing_info.connect_timing.connect_end); |
| 1586 | // Ensure that the mock clock advanced at all. |
| 1587 | EXPECT_EQ(base::TimeTicks::Now() - load_timing_info.receive_headers_start, |
| 1588 | kDelayAfter100Response); |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1589 | |
| 1590 | std::string response_data; |
| 1591 | rv = ReadTransaction(&trans, &response_data); |
| 1592 | EXPECT_THAT(rv, IsOk()); |
| 1593 | EXPECT_EQ("hello world", response_data); |
| 1594 | } |
| 1595 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1596 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForHttp) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1597 | Check100ResponseTiming(false /* use_spdy */); |
| 1598 | } |
| 1599 | |
Andrew Comminos | 517a92c | 2019-01-14 17:49:56 | [diff] [blame] | 1600 | TEST_F(HttpNetworkTransactionTest, MeasuresTimeToFirst100ResponseForSpdy) { |
Andrew Comminos | 1f2ff1cc | 2018-12-14 05:22:38 | [diff] [blame] | 1601 | Check100ResponseTiming(true /* use_spdy */); |
| 1602 | } |
| 1603 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1604 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1605 | HttpRequestInfo request; |
| 1606 | request.method = "POST"; |
| 1607 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1608 | request.traffic_annotation = |
| 1609 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1610 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1611 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1612 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1613 | |
| 1614 | MockRead data_reads[] = { |
| 1615 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1616 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1617 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1618 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1619 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1620 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1621 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1622 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1623 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1624 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1625 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1626 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1627 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1628 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1629 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1630 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1631 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1632 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1633 | } |
| 1634 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1635 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1636 | HttpRequestInfo request; |
| 1637 | request.method = "POST"; |
| 1638 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1639 | request.traffic_annotation = |
| 1640 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1641 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1642 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1643 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1644 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1645 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1646 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1647 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1648 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1649 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1650 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1651 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1652 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1653 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1654 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1655 | |
| 1656 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1657 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1658 | } |
| 1659 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1660 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1661 | const MockWrite* write_failure, |
| 1662 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1663 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1664 | request.method = "GET"; |
| 1665 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1666 | request.traffic_annotation = |
| 1667 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1668 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1669 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1670 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1671 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1672 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1673 | // Written data for successfully sending both requests. |
| 1674 | MockWrite data1_writes[] = { |
| 1675 | MockWrite("GET / HTTP/1.1\r\n" |
| 1676 | "Host: www.foo.com\r\n" |
| 1677 | "Connection: keep-alive\r\n\r\n"), |
| 1678 | MockWrite("GET / HTTP/1.1\r\n" |
| 1679 | "Host: www.foo.com\r\n" |
| 1680 | "Connection: keep-alive\r\n\r\n") |
| 1681 | }; |
| 1682 | |
| 1683 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1684 | MockRead data1_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("hello"), |
[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 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1689 | |
| 1690 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1691 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1692 | data1_writes[1] = *write_failure; |
| 1693 | } else { |
| 1694 | ASSERT_TRUE(read_failure); |
| 1695 | data1_reads[2] = *read_failure; |
| 1696 | } |
| 1697 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1698 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1699 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1700 | |
| 1701 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1702 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1703 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1704 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1705 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1706 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1707 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1708 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1709 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1710 | "hello", "world" |
| 1711 | }; |
| 1712 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1713 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1714 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1715 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1716 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1717 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1718 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1719 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1720 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1721 | |
| 1722 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1723 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1724 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1725 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1726 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1727 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1728 | if (i == 0) { |
| 1729 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1730 | } else { |
| 1731 | // The second request should be using a new socket. |
| 1732 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1733 | } |
| 1734 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1735 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1736 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1737 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1738 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1739 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1740 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1741 | |
| 1742 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1743 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1744 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1745 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1746 | } |
| 1747 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1748 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1749 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1750 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1751 | const MockRead* read_failure, |
| 1752 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1753 | HttpRequestInfo request; |
| 1754 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1755 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1756 | request.traffic_annotation = |
| 1757 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1758 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1759 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1760 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1761 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1762 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1763 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1764 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1765 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1766 | ssl1.next_proto = kProtoHTTP2; |
| 1767 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1768 | } |
| 1769 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1770 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1771 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1772 | // SPDY versions of the request and response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1773 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1774 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1775 | spdy::SpdySerializedFrame spdy_response( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1776 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1777 | spdy::SpdySerializedFrame spdy_data( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 1778 | spdy_util_.ConstructSpdyDataFrame(1, "hello", true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1779 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1780 | // HTTP/1.1 versions of the request and response. |
| 1781 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1782 | "Host: www.foo.com\r\n" |
| 1783 | "Connection: keep-alive\r\n\r\n"; |
| 1784 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1785 | const char kHttpData[] = "hello"; |
| 1786 | |
| 1787 | std::vector<MockRead> data1_reads; |
| 1788 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1789 | if (write_failure) { |
| 1790 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1791 | data1_writes.push_back(*write_failure); |
| 1792 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1793 | } else { |
| 1794 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1795 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1796 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1797 | } else { |
| 1798 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1799 | } |
| 1800 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1801 | } |
| 1802 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1803 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1804 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1805 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1806 | std::vector<MockRead> data2_reads; |
| 1807 | std::vector<MockWrite> data2_writes; |
| 1808 | |
| 1809 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1810 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1811 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1812 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1813 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1814 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1815 | } else { |
| 1816 | data2_writes.push_back( |
| 1817 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1818 | |
| 1819 | data2_reads.push_back( |
| 1820 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1821 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1822 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1823 | } |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1824 | SequencedSocketData data2(data2_reads, data2_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1825 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1826 | |
| 1827 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1828 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1829 | // Wait for the preconnect to complete. |
| 1830 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1831 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1832 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1833 | |
| 1834 | // Make the request. |
| 1835 | TestCompletionCallback callback; |
| 1836 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1837 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1838 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1839 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1840 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1841 | |
| 1842 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1843 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1844 | |
| 1845 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1846 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1847 | TestLoadTimingNotReused( |
| 1848 | load_timing_info, |
| 1849 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1850 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1851 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1852 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1853 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1854 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1855 | if (response->was_fetched_via_spdy) { |
| 1856 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1857 | } else { |
| 1858 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1859 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1860 | |
| 1861 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1862 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1863 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1864 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1865 | } |
| 1866 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1867 | // Test that we do not retry indefinitely when a server sends an error like |
| 1868 | // ERR_SPDY_PING_FAILED, ERR_SPDY_SERVER_REFUSED_STREAM, |
| 1869 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1870 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1871 | HttpRequestInfo request; |
| 1872 | request.method = "GET"; |
| 1873 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1874 | request.traffic_annotation = |
| 1875 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1876 | |
| 1877 | // Check whether we give up after the third try. |
| 1878 | |
| 1879 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1880 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1881 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1882 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1883 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1884 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1885 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1886 | |
| 1887 | // Three go away responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1888 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1889 | StaticSocketDataProvider data2(data_read1, data_write); |
| 1890 | StaticSocketDataProvider data3(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1891 | |
| 1892 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1893 | AddSSLSocketData(); |
| 1894 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1895 | AddSSLSocketData(); |
| 1896 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1897 | AddSSLSocketData(); |
| 1898 | |
| 1899 | TestCompletionCallback callback; |
| 1900 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1901 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1902 | |
| 1903 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1904 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1905 | |
| 1906 | rv = callback.WaitForResult(); |
| 1907 | EXPECT_THAT(rv, IsError(ERR_SPDY_SERVER_REFUSED_STREAM)); |
| 1908 | } |
| 1909 | |
| 1910 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1911 | HttpRequestInfo request; |
| 1912 | request.method = "GET"; |
| 1913 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1914 | request.traffic_annotation = |
| 1915 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1916 | |
| 1917 | // Check whether we try atleast thrice before giving up. |
| 1918 | |
| 1919 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1920 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1921 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1922 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1923 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1924 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1925 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1926 | |
| 1927 | // Construct a non error HTTP2 response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1928 | spdy::SpdySerializedFrame spdy_response_no_error( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1929 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1930 | spdy::SpdySerializedFrame spdy_data( |
| 1931 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1932 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1933 | CreateMockRead(spdy_data, 2)}; |
| 1934 | |
| 1935 | // Two error responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1936 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1937 | StaticSocketDataProvider data2(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1938 | // Followed by a success response. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1939 | SequencedSocketData data3(data_read2, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1940 | |
| 1941 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1942 | AddSSLSocketData(); |
| 1943 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1944 | AddSSLSocketData(); |
| 1945 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1946 | AddSSLSocketData(); |
| 1947 | |
| 1948 | TestCompletionCallback callback; |
| 1949 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1950 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1951 | |
| 1952 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1953 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1954 | |
| 1955 | rv = callback.WaitForResult(); |
| 1956 | EXPECT_THAT(rv, IsOk()); |
| 1957 | } |
| 1958 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1959 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1960 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1961 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1962 | } |
| 1963 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1964 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1965 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1966 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1967 | } |
| 1968 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1969 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1970 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1971 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1972 | } |
| 1973 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1974 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1975 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1976 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1977 | MockRead read_failure(SYNCHRONOUS, |
| 1978 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1979 | "Connection: Keep-Alive\r\n" |
| 1980 | "Content-Length: 6\r\n\r\n" |
| 1981 | "Pickle"); |
| 1982 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1983 | } |
| 1984 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1985 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1986 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1987 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1988 | } |
| 1989 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1990 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1991 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1992 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1993 | } |
| 1994 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1995 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1996 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1997 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1998 | } |
| 1999 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2000 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2001 | MockRead read_failure(ASYNC, OK); // EOF |
| 2002 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 2003 | } |
| 2004 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2005 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 2006 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2007 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 2008 | MockRead read_failure(SYNCHRONOUS, |
| 2009 | "HTTP/1.1 408 Request Timeout\r\n" |
| 2010 | "Connection: Keep-Alive\r\n" |
| 2011 | "Content-Length: 6\r\n\r\n" |
| 2012 | "Pickle"); |
| 2013 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 2014 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 2015 | } |
| 2016 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2017 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2018 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 2019 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 2020 | } |
| 2021 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2022 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2023 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 2024 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 2025 | } |
| 2026 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2027 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2028 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 2029 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 2030 | } |
| 2031 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2032 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 2033 | MockRead read_failure(ASYNC, OK); // EOF |
| 2034 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 2035 | } |
| 2036 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2037 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2038 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2039 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2040 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2041 | request.traffic_annotation = |
| 2042 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2043 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2044 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2045 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2046 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2047 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2048 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2049 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2050 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2051 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2052 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2053 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2054 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2055 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2056 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2057 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2058 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2059 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2060 | |
| 2061 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2062 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2063 | |
| 2064 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2065 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2066 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2067 | } |
| 2068 | |
| 2069 | // What do various browsers do when the server closes a non-keepalive |
| 2070 | // connection without sending any response header or body? |
| 2071 | // |
| 2072 | // IE7: error page |
| 2073 | // Safari 3.1.2 (Windows): error page |
| 2074 | // Firefox 3.0.1: blank page |
| 2075 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2076 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 2077 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2078 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2079 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2080 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 2081 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 2082 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2083 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2084 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2085 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2086 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 2087 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 2088 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2089 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 2090 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 2091 | // destructor in such situations. |
| 2092 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2093 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2094 | HttpRequestInfo request; |
| 2095 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2096 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2097 | request.traffic_annotation = |
| 2098 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2099 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2100 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2101 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2102 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2103 | |
| 2104 | MockRead data_reads[] = { |
| 2105 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2106 | MockRead("Connection: keep-alive\r\n"), |
| 2107 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2108 | MockRead("hello"), |
| 2109 | MockRead(SYNCHRONOUS, 0), |
| 2110 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2111 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2112 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2113 | |
| 2114 | TestCompletionCallback callback; |
| 2115 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2116 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2117 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2118 | |
| 2119 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2120 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2121 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2122 | scoped_refptr<IOBufferWithSize> io_buf = |
| 2123 | base::MakeRefCounted<IOBufferWithSize>(100); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2124 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2125 | if (rv == ERR_IO_PENDING) |
| 2126 | rv = callback.WaitForResult(); |
| 2127 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2128 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2129 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2130 | |
| 2131 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2132 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2133 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2134 | } |
| 2135 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2136 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2137 | HttpRequestInfo request; |
| 2138 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2139 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2140 | request.traffic_annotation = |
| 2141 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2142 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2143 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2144 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2145 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2146 | |
| 2147 | MockRead data_reads[] = { |
| 2148 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2149 | MockRead("Connection: keep-alive\r\n"), |
| 2150 | MockRead("Content-Length: 100\r\n\r\n"), |
| 2151 | MockRead(SYNCHRONOUS, 0), |
| 2152 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2153 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2154 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2155 | |
| 2156 | TestCompletionCallback callback; |
| 2157 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2158 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2159 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2160 | |
| 2161 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2162 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2163 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 2164 | scoped_refptr<IOBufferWithSize> io_buf( |
| 2165 | base::MakeRefCounted<IOBufferWithSize>(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 2166 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2167 | if (rv == ERR_IO_PENDING) |
| 2168 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2169 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2170 | |
| 2171 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 2172 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 2173 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2174 | } |
| 2175 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2176 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 2177 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2178 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2179 | HttpRequestInfo request; |
| 2180 | request.method = "GET"; |
| 2181 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2182 | request.traffic_annotation = |
| 2183 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2184 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2185 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2186 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2187 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2188 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2189 | const char* request_data = |
| 2190 | "GET / HTTP/1.1\r\n" |
| 2191 | "Host: www.foo.com\r\n" |
| 2192 | "Connection: keep-alive\r\n\r\n"; |
| 2193 | MockWrite data_writes[] = { |
| 2194 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 2195 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 2196 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 2197 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 2198 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 2199 | }; |
| 2200 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2201 | // Note that because all these reads happen in the same |
| 2202 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 2203 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2204 | MockRead data_reads[] = { |
| 2205 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 2206 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 2207 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 2208 | MockRead(ASYNC, 7, |
| 2209 | "HTTP/1.1 302 Found\r\n" |
| 2210 | "Content-Length: 0\r\n\r\n"), |
| 2211 | MockRead(ASYNC, 9, |
| 2212 | "HTTP/1.1 302 Found\r\n" |
| 2213 | "Content-Length: 5\r\n\r\n" |
| 2214 | "hello"), |
| 2215 | MockRead(ASYNC, 11, |
| 2216 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2217 | "Content-Length: 0\r\n\r\n"), |
| 2218 | MockRead(ASYNC, 13, |
| 2219 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 2220 | "Content-Length: 5\r\n\r\n" |
| 2221 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2222 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2223 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 2224 | // the set_busy_before_sync_reads(true) call, while the |
| 2225 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 2226 | // reuseable. See http://crbug.com/544255. |
| 2227 | MockRead(ASYNC, 15, |
| 2228 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2229 | "Content-Length: 5\r\n\r\n"), |
| 2230 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2231 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2232 | MockRead(ASYNC, 18, |
| 2233 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 2234 | "Content-Length: 5\r\n\r\n" |
| 2235 | "he"), |
| 2236 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 2237 | |
| 2238 | // The body of the final request is actually read. |
| 2239 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 2240 | MockRead(ASYNC, 22, "hello"), |
| 2241 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2242 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2243 | data.set_busy_before_sync_reads(true); |
| 2244 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2245 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2246 | const int kNumUnreadBodies = base::size(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2247 | std::string response_lines[kNumUnreadBodies]; |
| 2248 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 2249 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2250 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2251 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2252 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2253 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2254 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2255 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2256 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2257 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2258 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2259 | LoadTimingInfo load_timing_info; |
| 2260 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2261 | if (i == 0) { |
| 2262 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2263 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2264 | } else { |
| 2265 | TestLoadTimingReused(load_timing_info); |
| 2266 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2267 | } |
| 2268 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2269 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2270 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2271 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2272 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2273 | response_lines[i] = response->headers->GetStatusLine(); |
| 2274 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2275 | // Delete the transaction without reading the response bodies. Then spin |
| 2276 | // the message loop, so the response bodies are drained. |
| 2277 | trans.reset(); |
| 2278 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2279 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2280 | |
| 2281 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2282 | "HTTP/1.1 204 No Content", |
| 2283 | "HTTP/1.1 205 Reset Content", |
| 2284 | "HTTP/1.1 304 Not Modified", |
| 2285 | "HTTP/1.1 302 Found", |
| 2286 | "HTTP/1.1 302 Found", |
| 2287 | "HTTP/1.1 301 Moved Permanently", |
| 2288 | "HTTP/1.1 301 Moved Permanently", |
| 2289 | "HTTP/1.1 200 Hunky-Dory", |
| 2290 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2291 | }; |
| 2292 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 2293 | static_assert(kNumUnreadBodies == base::size(kStatusLines), |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2294 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2295 | |
| 2296 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2297 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2298 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2299 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2300 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2301 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2302 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2303 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2304 | ASSERT_TRUE(response); |
| 2305 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2306 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2307 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2308 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2309 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2310 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2311 | } |
| 2312 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2313 | // Sockets that receive extra data after a response is complete should not be |
| 2314 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2315 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2316 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2317 | MockWrite data_writes1[] = { |
| 2318 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2319 | "Host: www.borked.com\r\n" |
| 2320 | "Connection: keep-alive\r\n\r\n"), |
| 2321 | }; |
| 2322 | |
| 2323 | MockRead data_reads1[] = { |
| 2324 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2325 | "Connection: keep-alive\r\n" |
| 2326 | "Content-Length: 22\r\n\r\n" |
| 2327 | "This server is borked."), |
| 2328 | }; |
| 2329 | |
| 2330 | MockWrite data_writes2[] = { |
| 2331 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2332 | "Host: www.borked.com\r\n" |
| 2333 | "Connection: keep-alive\r\n\r\n"), |
| 2334 | }; |
| 2335 | |
| 2336 | MockRead data_reads2[] = { |
| 2337 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2338 | "Content-Length: 3\r\n\r\n" |
| 2339 | "foo"), |
| 2340 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2341 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2342 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2343 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2344 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2345 | |
| 2346 | TestCompletionCallback callback; |
| 2347 | HttpRequestInfo request1; |
| 2348 | request1.method = "HEAD"; |
| 2349 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2350 | request1.traffic_annotation = |
| 2351 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2352 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2353 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2354 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2355 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2356 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2357 | |
| 2358 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2359 | ASSERT_TRUE(response1); |
| 2360 | ASSERT_TRUE(response1->headers); |
| 2361 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2362 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2363 | |
| 2364 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2365 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2366 | EXPECT_EQ("", response_data1); |
| 2367 | // Deleting the transaction attempts to release the socket back into the |
| 2368 | // socket pool. |
| 2369 | trans1.reset(); |
| 2370 | |
| 2371 | HttpRequestInfo request2; |
| 2372 | request2.method = "GET"; |
| 2373 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2374 | request2.traffic_annotation = |
| 2375 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2376 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2377 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2378 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2379 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2380 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2381 | |
| 2382 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2383 | ASSERT_TRUE(response2); |
| 2384 | ASSERT_TRUE(response2->headers); |
| 2385 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2386 | |
| 2387 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2388 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2389 | EXPECT_EQ("foo", response_data2); |
| 2390 | } |
| 2391 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2392 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2393 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2394 | MockWrite data_writes1[] = { |
| 2395 | MockWrite("GET / HTTP/1.1\r\n" |
| 2396 | "Host: www.borked.com\r\n" |
| 2397 | "Connection: keep-alive\r\n\r\n"), |
| 2398 | }; |
| 2399 | |
| 2400 | MockRead data_reads1[] = { |
| 2401 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2402 | "Connection: keep-alive\r\n" |
| 2403 | "Content-Length: 22\r\n\r\n" |
| 2404 | "This server is borked." |
| 2405 | "Bonus data!"), |
| 2406 | }; |
| 2407 | |
| 2408 | MockWrite data_writes2[] = { |
| 2409 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2410 | "Host: www.borked.com\r\n" |
| 2411 | "Connection: keep-alive\r\n\r\n"), |
| 2412 | }; |
| 2413 | |
| 2414 | MockRead data_reads2[] = { |
| 2415 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2416 | "Content-Length: 3\r\n\r\n" |
| 2417 | "foo"), |
| 2418 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2419 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2420 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2421 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2422 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2423 | |
| 2424 | TestCompletionCallback callback; |
| 2425 | HttpRequestInfo request1; |
| 2426 | request1.method = "GET"; |
| 2427 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2428 | request1.traffic_annotation = |
| 2429 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2430 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2431 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2432 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2433 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2434 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2435 | |
| 2436 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2437 | ASSERT_TRUE(response1); |
| 2438 | ASSERT_TRUE(response1->headers); |
| 2439 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2440 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2441 | |
| 2442 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2443 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2444 | EXPECT_EQ("This server is borked.", response_data1); |
| 2445 | // Deleting the transaction attempts to release the socket back into the |
| 2446 | // socket pool. |
| 2447 | trans1.reset(); |
| 2448 | |
| 2449 | HttpRequestInfo request2; |
| 2450 | request2.method = "GET"; |
| 2451 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2452 | request2.traffic_annotation = |
| 2453 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2454 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2455 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2456 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2457 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2458 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2459 | |
| 2460 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2461 | ASSERT_TRUE(response2); |
| 2462 | ASSERT_TRUE(response2->headers); |
| 2463 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2464 | |
| 2465 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2466 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2467 | EXPECT_EQ("foo", response_data2); |
| 2468 | } |
| 2469 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2470 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2471 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2472 | MockWrite data_writes1[] = { |
| 2473 | MockWrite("GET / HTTP/1.1\r\n" |
| 2474 | "Host: www.borked.com\r\n" |
| 2475 | "Connection: keep-alive\r\n\r\n"), |
| 2476 | }; |
| 2477 | |
| 2478 | MockRead data_reads1[] = { |
| 2479 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2480 | "Connection: keep-alive\r\n" |
| 2481 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2482 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2483 | MockRead("0\r\n\r\nBonus data!"), |
| 2484 | }; |
| 2485 | |
| 2486 | MockWrite data_writes2[] = { |
| 2487 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2488 | "Host: www.borked.com\r\n" |
| 2489 | "Connection: keep-alive\r\n\r\n"), |
| 2490 | }; |
| 2491 | |
| 2492 | MockRead data_reads2[] = { |
| 2493 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2494 | "Content-Length: 3\r\n\r\n" |
| 2495 | "foo"), |
| 2496 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2497 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2498 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2499 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2500 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2501 | |
| 2502 | TestCompletionCallback callback; |
| 2503 | HttpRequestInfo request1; |
| 2504 | request1.method = "GET"; |
| 2505 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2506 | request1.traffic_annotation = |
| 2507 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2508 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2509 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2510 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2511 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2512 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2513 | |
| 2514 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2515 | ASSERT_TRUE(response1); |
| 2516 | ASSERT_TRUE(response1->headers); |
| 2517 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2518 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2519 | |
| 2520 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2521 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2522 | EXPECT_EQ("This server is borked.", response_data1); |
| 2523 | // Deleting the transaction attempts to release the socket back into the |
| 2524 | // socket pool. |
| 2525 | trans1.reset(); |
| 2526 | |
| 2527 | HttpRequestInfo request2; |
| 2528 | request2.method = "GET"; |
| 2529 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2530 | request2.traffic_annotation = |
| 2531 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2532 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2533 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2534 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2535 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2536 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2537 | |
| 2538 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2539 | ASSERT_TRUE(response2); |
| 2540 | ASSERT_TRUE(response2->headers); |
| 2541 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2542 | |
| 2543 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2544 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2545 | EXPECT_EQ("foo", response_data2); |
| 2546 | } |
| 2547 | |
| 2548 | // This is a little different from the others - it tests the case that the |
| 2549 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2550 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2551 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2552 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2553 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2554 | MockWrite data_writes1[] = { |
| 2555 | MockWrite("GET / HTTP/1.1\r\n" |
| 2556 | "Host: www.borked.com\r\n" |
| 2557 | "Connection: keep-alive\r\n\r\n"), |
| 2558 | }; |
| 2559 | |
| 2560 | MockRead data_reads1[] = { |
| 2561 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2562 | "Connection: keep-alive\r\n" |
| 2563 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2564 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2565 | MockRead("0\r\n\r\nBonus data!"), |
| 2566 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2567 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2568 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2569 | |
| 2570 | TestCompletionCallback callback; |
| 2571 | HttpRequestInfo request1; |
| 2572 | request1.method = "GET"; |
| 2573 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2574 | request1.traffic_annotation = |
| 2575 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2576 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2577 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2578 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2579 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2580 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2581 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2582 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2583 | ASSERT_TRUE(response1); |
| 2584 | ASSERT_TRUE(response1->headers); |
| 2585 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2586 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2587 | |
| 2588 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2589 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2590 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2591 | |
| 2592 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2593 | // socket can't be reused, rather than returning it to the socket pool. |
| 2594 | base::RunLoop().RunUntilIdle(); |
| 2595 | |
| 2596 | // There should be no idle sockets in the pool. |
| 2597 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2598 | } |
| 2599 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2600 | // Test the request-challenge-retry sequence for basic auth. |
| 2601 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2602 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2603 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2604 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2605 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2606 | request.traffic_annotation = |
| 2607 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2608 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2609 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2610 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2611 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2612 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2613 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2614 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2615 | MockWrite( |
| 2616 | "GET / HTTP/1.1\r\n" |
| 2617 | "Host: www.example.org\r\n" |
| 2618 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2619 | }; |
| 2620 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2621 | MockRead data_reads1[] = { |
| 2622 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2623 | // Give a couple authenticate options (only the middle one is actually |
| 2624 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2625 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2626 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2627 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2628 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2629 | // Large content-length -- won't matter, as connection will be reset. |
| 2630 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2631 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2632 | }; |
| 2633 | |
| 2634 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2635 | // be issuing -- the final header line contains the credentials. |
| 2636 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2637 | MockWrite( |
| 2638 | "GET / HTTP/1.1\r\n" |
| 2639 | "Host: www.example.org\r\n" |
| 2640 | "Connection: keep-alive\r\n" |
| 2641 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2642 | }; |
| 2643 | |
| 2644 | // Lastly, the server responds with the actual content. |
| 2645 | MockRead data_reads2[] = { |
| 2646 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2647 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2648 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2649 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2650 | }; |
| 2651 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2652 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2653 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2654 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2655 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2656 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2657 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2658 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2659 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2660 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2661 | |
| 2662 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2663 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2664 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2665 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2666 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2667 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2668 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2669 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2670 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2671 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2672 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2673 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2674 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2675 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2676 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2677 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2678 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2679 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2680 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2681 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2682 | |
| 2683 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2684 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2685 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2686 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2687 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2688 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2689 | // The load timing after restart should have a new socket ID, and times after |
| 2690 | // those of the first load timing. |
| 2691 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2692 | load_timing_info2.connect_timing.connect_start); |
| 2693 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2694 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2695 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2696 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2697 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2698 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2699 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2700 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2701 | ASSERT_TRUE(response); |
| 2702 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2703 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2704 | } |
| 2705 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2706 | // Test the request-challenge-retry sequence for basic auth. |
| 2707 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2708 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2709 | HttpRequestInfo request; |
| 2710 | request.method = "GET"; |
| 2711 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2712 | request.traffic_annotation = |
| 2713 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2714 | |
| 2715 | TestNetLog log; |
| 2716 | MockHostResolver* resolver = new MockHostResolver(); |
| 2717 | session_deps_.net_log = &log; |
| 2718 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2719 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2720 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2721 | |
| 2722 | resolver->rules()->ClearRules(); |
| 2723 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2724 | |
| 2725 | MockWrite data_writes1[] = { |
| 2726 | MockWrite("GET / HTTP/1.1\r\n" |
| 2727 | "Host: www.example.org\r\n" |
| 2728 | "Connection: keep-alive\r\n\r\n"), |
| 2729 | }; |
| 2730 | |
| 2731 | MockRead data_reads1[] = { |
| 2732 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2733 | // Give a couple authenticate options (only the middle one is actually |
| 2734 | // supported). |
| 2735 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2736 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2737 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2738 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2739 | // Large content-length -- won't matter, as connection will be reset. |
| 2740 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2741 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2742 | }; |
| 2743 | |
| 2744 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2745 | // be issuing -- the final header line contains the credentials. |
| 2746 | MockWrite data_writes2[] = { |
| 2747 | MockWrite("GET / HTTP/1.1\r\n" |
| 2748 | "Host: www.example.org\r\n" |
| 2749 | "Connection: keep-alive\r\n" |
| 2750 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2751 | }; |
| 2752 | |
| 2753 | // Lastly, the server responds with the actual content. |
| 2754 | MockRead data_reads2[] = { |
| 2755 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2756 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2757 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2758 | }; |
| 2759 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2760 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2761 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2762 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2763 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2764 | |
| 2765 | TestCompletionCallback callback1; |
| 2766 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2767 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2768 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2769 | |
| 2770 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2771 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2772 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2773 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2774 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2775 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2776 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2777 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2778 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2779 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2780 | ASSERT_TRUE(response); |
| 2781 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2782 | |
| 2783 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2784 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2785 | ASSERT_FALSE(endpoint.address().empty()); |
| 2786 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2787 | |
| 2788 | resolver->rules()->ClearRules(); |
| 2789 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2790 | |
| 2791 | TestCompletionCallback callback2; |
| 2792 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2793 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2794 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2795 | |
| 2796 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2797 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2798 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2799 | // The load timing after restart should have a new socket ID, and times after |
| 2800 | // those of the first load timing. |
| 2801 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2802 | load_timing_info2.connect_timing.connect_start); |
| 2803 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2804 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2805 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2806 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2807 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2808 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2809 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2810 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2811 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2812 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2813 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2814 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2815 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2816 | ASSERT_FALSE(endpoint.address().empty()); |
| 2817 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2818 | } |
| 2819 | |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2820 | // Test that, if the server requests auth indefinitely, HttpNetworkTransaction |
| 2821 | // will eventually give up. |
| 2822 | TEST_F(HttpNetworkTransactionTest, BasicAuthForever) { |
| 2823 | HttpRequestInfo request; |
| 2824 | request.method = "GET"; |
| 2825 | request.url = GURL("http://www.example.org/"); |
| 2826 | request.traffic_annotation = |
| 2827 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2828 | |
| 2829 | TestNetLog log; |
| 2830 | session_deps_.net_log = &log; |
| 2831 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2832 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 2833 | |
| 2834 | MockWrite data_writes[] = { |
| 2835 | MockWrite("GET / HTTP/1.1\r\n" |
| 2836 | "Host: www.example.org\r\n" |
| 2837 | "Connection: keep-alive\r\n\r\n"), |
| 2838 | }; |
| 2839 | |
| 2840 | MockRead data_reads[] = { |
| 2841 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2842 | // Give a couple authenticate options (only the middle one is actually |
| 2843 | // supported). |
| 2844 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2845 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2846 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2847 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2848 | // Large content-length -- won't matter, as connection will be reset. |
| 2849 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2850 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2851 | }; |
| 2852 | |
| 2853 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2854 | // be issuing -- the final header line contains the credentials. |
| 2855 | MockWrite data_writes_restart[] = { |
| 2856 | MockWrite("GET / HTTP/1.1\r\n" |
| 2857 | "Host: www.example.org\r\n" |
| 2858 | "Connection: keep-alive\r\n" |
| 2859 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2860 | }; |
| 2861 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2862 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2863 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2864 | |
| 2865 | TestCompletionCallback callback; |
| 2866 | int rv = callback.GetResult( |
| 2867 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 2868 | |
| 2869 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_restarts; |
| 2870 | for (int i = 0; i < 32; i++) { |
| 2871 | // Check the previous response was a 401. |
| 2872 | EXPECT_THAT(rv, IsOk()); |
| 2873 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 2874 | ASSERT_TRUE(response); |
| 2875 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2876 | |
| 2877 | data_restarts.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2878 | data_reads, data_writes_restart)); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2879 | session_deps_.socket_factory->AddSocketDataProvider( |
| 2880 | data_restarts.back().get()); |
| 2881 | rv = callback.GetResult(trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2882 | callback.callback())); |
| 2883 | } |
| 2884 | |
| 2885 | // After too many tries, the transaction should have given up. |
| 2886 | EXPECT_THAT(rv, IsError(ERR_TOO_MANY_RETRIES)); |
| 2887 | } |
| 2888 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2889 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2890 | HttpRequestInfo request; |
| 2891 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2892 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2893 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2894 | request.traffic_annotation = |
| 2895 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2896 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2897 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2898 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2899 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2900 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2901 | MockWrite( |
| 2902 | "GET / HTTP/1.1\r\n" |
| 2903 | "Host: www.example.org\r\n" |
| 2904 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2905 | }; |
| 2906 | |
| 2907 | MockRead data_reads[] = { |
| 2908 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2909 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2910 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2911 | // Large content-length -- won't matter, as connection will be reset. |
| 2912 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2913 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2914 | }; |
| 2915 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2916 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2917 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2918 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2919 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2920 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2921 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2922 | |
| 2923 | rv = callback.WaitForResult(); |
| 2924 | EXPECT_EQ(0, rv); |
| 2925 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2926 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2927 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2928 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2929 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2930 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2931 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2932 | ASSERT_TRUE(response); |
| 2933 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2934 | } |
| 2935 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2936 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2937 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2938 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2939 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2940 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2941 | // reused. See http://crbug.com/544255. |
| 2942 | for (int i = 0; i < 2; ++i) { |
| 2943 | HttpRequestInfo request; |
| 2944 | request.method = "GET"; |
| 2945 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2946 | request.traffic_annotation = |
| 2947 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2948 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2949 | TestNetLog log; |
| 2950 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2951 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2952 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2953 | MockWrite data_writes[] = { |
| 2954 | MockWrite(ASYNC, 0, |
| 2955 | "GET / HTTP/1.1\r\n" |
| 2956 | "Host: www.example.org\r\n" |
| 2957 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2958 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2959 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2960 | // be issuing -- the final header line contains the credentials. |
| 2961 | MockWrite(ASYNC, 6, |
| 2962 | "GET / HTTP/1.1\r\n" |
| 2963 | "Host: www.example.org\r\n" |
| 2964 | "Connection: keep-alive\r\n" |
| 2965 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2966 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2967 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2968 | MockRead data_reads[] = { |
| 2969 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2970 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2971 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2972 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2973 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2974 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2975 | // Lastly, the server responds with the actual content. |
| 2976 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2977 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2978 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2979 | MockRead(ASYNC, 10, "Hello"), |
| 2980 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2981 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2982 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2983 | data.set_busy_before_sync_reads(true); |
| 2984 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2985 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2986 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2987 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2988 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2989 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2990 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2991 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2992 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2993 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2994 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2995 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2996 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2997 | ASSERT_TRUE(response); |
| 2998 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2999 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3000 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 3001 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3002 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 3003 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3004 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3005 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3006 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3007 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3008 | TestLoadTimingReused(load_timing_info2); |
| 3009 | // The load timing after restart should have the same socket ID, and times |
| 3010 | // those of the first load timing. |
| 3011 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 3012 | load_timing_info2.send_start); |
| 3013 | 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] | 3014 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3015 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3016 | ASSERT_TRUE(response); |
| 3017 | EXPECT_FALSE(response->auth_challenge); |
| 3018 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3019 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3020 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3021 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3022 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3023 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3024 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3025 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3026 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 3027 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3028 | } |
| 3029 | |
| 3030 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3031 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3032 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3033 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3034 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3035 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3036 | request.traffic_annotation = |
| 3037 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3038 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3039 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3040 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3041 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3042 | MockWrite("GET / HTTP/1.1\r\n" |
| 3043 | "Host: www.example.org\r\n" |
| 3044 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3045 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3046 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3047 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3048 | MockWrite("GET / HTTP/1.1\r\n" |
| 3049 | "Host: www.example.org\r\n" |
| 3050 | "Connection: keep-alive\r\n" |
| 3051 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3052 | }; |
| 3053 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3054 | MockRead data_reads1[] = { |
| 3055 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3056 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3057 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3058 | |
| 3059 | // Lastly, the server responds with the actual content. |
| 3060 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3061 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3062 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3063 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3064 | }; |
| 3065 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3066 | // An incorrect reconnect would cause this to be read. |
| 3067 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3068 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3069 | }; |
| 3070 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3071 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3072 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3073 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3074 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3075 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3076 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3077 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3078 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3079 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3080 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3081 | |
| 3082 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3083 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3084 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3085 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3086 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3087 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3088 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3089 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3090 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3091 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3092 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3093 | |
| 3094 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3095 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3096 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3097 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3098 | ASSERT_TRUE(response); |
| 3099 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3100 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3101 | } |
| 3102 | |
| 3103 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3104 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3105 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3106 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3107 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3108 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3109 | request.traffic_annotation = |
| 3110 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3111 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3112 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3113 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3114 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3115 | MockWrite("GET / HTTP/1.1\r\n" |
| 3116 | "Host: www.example.org\r\n" |
| 3117 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3118 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3119 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3120 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3121 | MockWrite("GET / HTTP/1.1\r\n" |
| 3122 | "Host: www.example.org\r\n" |
| 3123 | "Connection: keep-alive\r\n" |
| 3124 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3125 | }; |
| 3126 | |
| 3127 | // Respond with 5 kb of response body. |
| 3128 | std::string large_body_string("Unauthorized"); |
| 3129 | large_body_string.append(5 * 1024, ' '); |
| 3130 | large_body_string.append("\r\n"); |
| 3131 | |
| 3132 | MockRead data_reads1[] = { |
| 3133 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3134 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3135 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3136 | // 5134 = 12 + 5 * 1024 + 2 |
| 3137 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3138 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3139 | |
| 3140 | // Lastly, the server responds with the actual content. |
| 3141 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3142 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3143 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3144 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3145 | }; |
| 3146 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3147 | // An incorrect reconnect would cause this to be read. |
| 3148 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3149 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 3150 | }; |
| 3151 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3152 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3153 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3154 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3155 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3156 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3157 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3158 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3159 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3160 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3161 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3162 | |
| 3163 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3164 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3165 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3166 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3167 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3168 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3169 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3170 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3171 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3172 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3173 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3174 | |
| 3175 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3176 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3177 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3178 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3179 | ASSERT_TRUE(response); |
| 3180 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3181 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3182 | } |
| 3183 | |
| 3184 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3185 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3186 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3187 | HttpRequestInfo request; |
| 3188 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3189 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3190 | request.traffic_annotation = |
| 3191 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3192 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3193 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3194 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3195 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3196 | MockWrite( |
| 3197 | "GET / HTTP/1.1\r\n" |
| 3198 | "Host: www.example.org\r\n" |
| 3199 | "Connection: keep-alive\r\n\r\n"), |
| 3200 | // This simulates the seemingly successful write to a closed connection |
| 3201 | // if the bug is not fixed. |
| 3202 | MockWrite( |
| 3203 | "GET / HTTP/1.1\r\n" |
| 3204 | "Host: www.example.org\r\n" |
| 3205 | "Connection: keep-alive\r\n" |
| 3206 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3207 | }; |
| 3208 | |
| 3209 | MockRead data_reads1[] = { |
| 3210 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 3211 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3212 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3213 | MockRead("Content-Length: 14\r\n\r\n"), |
| 3214 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3215 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3216 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3217 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3218 | }; |
| 3219 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3220 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3221 | // be issuing -- the final header line contains the credentials. |
| 3222 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3223 | MockWrite( |
| 3224 | "GET / HTTP/1.1\r\n" |
| 3225 | "Host: www.example.org\r\n" |
| 3226 | "Connection: keep-alive\r\n" |
| 3227 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3228 | }; |
| 3229 | |
| 3230 | // Lastly, the server responds with the actual content. |
| 3231 | MockRead data_reads2[] = { |
| 3232 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3233 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3234 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3235 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3236 | }; |
| 3237 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3238 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3239 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3240 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3241 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3242 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3243 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3244 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3245 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3246 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3247 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3248 | |
| 3249 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3250 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3251 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3252 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3253 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3254 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3255 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3256 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3257 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3258 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3259 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3260 | |
| 3261 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3262 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3263 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3264 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3265 | ASSERT_TRUE(response); |
| 3266 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3267 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3268 | } |
| 3269 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3270 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3271 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3272 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3273 | HttpRequestInfo request; |
| 3274 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3275 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3276 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3277 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3278 | request.traffic_annotation = |
| 3279 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3280 | |
| 3281 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3282 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3283 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3284 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3285 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3286 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3287 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3288 | |
| 3289 | // Since we have proxy, should try to establish tunnel. |
| 3290 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3291 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3292 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3293 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3294 | }; |
| 3295 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3296 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3297 | // connection. |
| 3298 | MockRead data_reads1[] = { |
| 3299 | // No credentials. |
| 3300 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3301 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3302 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3303 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3304 | // Since the first connection couldn't be reused, need to establish another |
| 3305 | // once given credentials. |
| 3306 | MockWrite data_writes2[] = { |
| 3307 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3308 | // be issuing -- the final header line contains the credentials. |
| 3309 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3310 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3311 | "Proxy-Connection: keep-alive\r\n" |
| 3312 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3313 | |
| 3314 | MockWrite("GET / HTTP/1.1\r\n" |
| 3315 | "Host: www.example.org\r\n" |
| 3316 | "Connection: keep-alive\r\n\r\n"), |
| 3317 | }; |
| 3318 | |
| 3319 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3320 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3321 | |
| 3322 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3323 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3324 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3325 | MockRead(SYNCHRONOUS, "hello"), |
| 3326 | }; |
| 3327 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3328 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3329 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3330 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3331 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3332 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3333 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3334 | |
| 3335 | TestCompletionCallback callback1; |
| 3336 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3337 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3338 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3339 | |
| 3340 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3341 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3342 | |
| 3343 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3344 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3345 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3346 | log.GetEntries(&entries); |
| 3347 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3348 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3349 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3350 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3351 | entries, pos, |
| 3352 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3353 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3354 | |
| 3355 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3356 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3357 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3358 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3359 | EXPECT_EQ(407, response->headers->response_code()); |
| 3360 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3361 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3362 | |
| 3363 | LoadTimingInfo load_timing_info; |
| 3364 | // CONNECT requests and responses are handled at the connect job level, so |
| 3365 | // the transaction does not yet have a connection. |
| 3366 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3367 | |
| 3368 | TestCompletionCallback callback2; |
| 3369 | |
| 3370 | rv = |
| 3371 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3372 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3373 | |
| 3374 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3375 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3376 | |
| 3377 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3378 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3379 | |
| 3380 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3381 | EXPECT_EQ(200, response->headers->response_code()); |
| 3382 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3383 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3384 | |
| 3385 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3386 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3387 | |
| 3388 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3389 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3390 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3391 | |
| 3392 | trans.reset(); |
| 3393 | session->CloseAllConnections(); |
| 3394 | } |
| 3395 | |
| 3396 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3397 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3398 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3399 | HttpRequestInfo request; |
| 3400 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3401 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3402 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3403 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3404 | request.traffic_annotation = |
| 3405 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3406 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3407 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3408 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3409 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3410 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3411 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3412 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3413 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3414 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3415 | // Since we have proxy, should try to establish tunnel. |
| 3416 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 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\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3420 | }; |
| 3421 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3422 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3423 | // connection. |
| 3424 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3425 | // No credentials. |
| 3426 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3427 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3428 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3429 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3430 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3431 | MockWrite data_writes2[] = { |
| 3432 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3433 | // be issuing -- the final header line contains the credentials. |
| 3434 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3435 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3436 | "Proxy-Connection: keep-alive\r\n" |
| 3437 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3438 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3439 | MockWrite("GET / HTTP/1.1\r\n" |
| 3440 | "Host: www.example.org\r\n" |
| 3441 | "Connection: keep-alive\r\n\r\n"), |
| 3442 | }; |
| 3443 | |
| 3444 | MockRead data_reads2[] = { |
| 3445 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3446 | |
| 3447 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3448 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3449 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3450 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3451 | }; |
| 3452 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3453 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3454 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3455 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3456 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3457 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3458 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3459 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3460 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3461 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3462 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3463 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3464 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3465 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3466 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3467 | |
| 3468 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3469 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3470 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3471 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3472 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3473 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3474 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3475 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3476 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3477 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3478 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3479 | |
| 3480 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3481 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3482 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3483 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3484 | EXPECT_EQ(407, response->headers->response_code()); |
| 3485 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3486 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3487 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3488 | LoadTimingInfo load_timing_info; |
| 3489 | // CONNECT requests and responses are handled at the connect job level, so |
| 3490 | // the transaction does not yet have a connection. |
| 3491 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3492 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3493 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3494 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3495 | rv = trans->RestartWithAuth( |
| 3496 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3497 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3498 | |
| 3499 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3500 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3501 | |
| 3502 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3503 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3504 | |
| 3505 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3506 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3507 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3508 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3509 | |
| 3510 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3511 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3512 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3513 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3514 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3515 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3516 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3517 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3518 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3519 | } |
| 3520 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3521 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3522 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3523 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3524 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3525 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3526 | // reused. See http://crbug.com/544255. |
| 3527 | for (int i = 0; i < 2; ++i) { |
| 3528 | HttpRequestInfo request; |
| 3529 | request.method = "GET"; |
| 3530 | request.url = GURL("https://www.example.org/"); |
| 3531 | // Ensure that proxy authentication is attempted even |
| 3532 | // when the no authentication data flag is set. |
| 3533 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3534 | request.traffic_annotation = |
| 3535 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3536 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3537 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3538 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3539 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3540 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3541 | BoundTestNetLog log; |
| 3542 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3543 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3544 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3545 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3546 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3547 | // Since we have proxy, should try to establish tunnel. |
| 3548 | MockWrite data_writes1[] = { |
| 3549 | MockWrite(ASYNC, 0, |
| 3550 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3551 | "Host: www.example.org:443\r\n" |
| 3552 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3553 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3554 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3555 | // be issuing -- the final header line contains the credentials. |
| 3556 | MockWrite(ASYNC, 3, |
| 3557 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3558 | "Host: www.example.org:443\r\n" |
| 3559 | "Proxy-Connection: keep-alive\r\n" |
| 3560 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3561 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3562 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3563 | // The proxy responds to the connect with a 407, using a persistent |
| 3564 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3565 | MockRead data_reads1[] = { |
| 3566 | // No credentials. |
| 3567 | MockRead(ASYNC, 1, |
| 3568 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3569 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3570 | "Proxy-Connection: keep-alive\r\n" |
| 3571 | "Content-Length: 10\r\n\r\n"), |
| 3572 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3573 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3574 | // Wrong credentials (wrong password). |
| 3575 | MockRead(ASYNC, 4, |
| 3576 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3577 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3578 | "Proxy-Connection: keep-alive\r\n" |
| 3579 | "Content-Length: 10\r\n\r\n"), |
| 3580 | // No response body because the test stops reading here. |
| 3581 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3582 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3583 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3584 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3585 | data1.set_busy_before_sync_reads(true); |
| 3586 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3587 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3588 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3589 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3590 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3591 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3592 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3593 | TestNetLogEntry::List entries; |
| 3594 | log.GetEntries(&entries); |
| 3595 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3596 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3597 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3598 | ExpectLogContainsSomewhere( |
| 3599 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3600 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3601 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3602 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3603 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3604 | ASSERT_TRUE(response); |
| 3605 | ASSERT_TRUE(response->headers); |
| 3606 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3607 | EXPECT_EQ(407, response->headers->response_code()); |
| 3608 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3609 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3610 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3611 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3612 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3613 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3614 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3615 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3616 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3617 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3618 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3619 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3620 | ASSERT_TRUE(response); |
| 3621 | ASSERT_TRUE(response->headers); |
| 3622 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3623 | EXPECT_EQ(407, response->headers->response_code()); |
| 3624 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3625 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3626 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3627 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3628 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3629 | // out of scope. |
| 3630 | session->CloseAllConnections(); |
| 3631 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3632 | } |
| 3633 | |
| 3634 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3635 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3636 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3637 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3638 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3639 | // reused. See http://crbug.com/544255. |
| 3640 | for (int i = 0; i < 2; ++i) { |
| 3641 | HttpRequestInfo request; |
| 3642 | request.method = "GET"; |
| 3643 | request.url = GURL("https://www.example.org/"); |
| 3644 | // Ensure that proxy authentication is attempted even |
| 3645 | // when the no authentication data flag is set. |
| 3646 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3647 | request.traffic_annotation = |
| 3648 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3649 | |
| 3650 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3651 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3652 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3653 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3654 | BoundTestNetLog log; |
| 3655 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3656 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3657 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3658 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3659 | |
| 3660 | // Since we have proxy, should try to establish tunnel. |
| 3661 | MockWrite data_writes1[] = { |
| 3662 | MockWrite(ASYNC, 0, |
| 3663 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3664 | "Host: www.example.org:443\r\n" |
| 3665 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3666 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3667 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3668 | // be issuing -- the final header line contains the credentials. |
| 3669 | MockWrite(ASYNC, 3, |
| 3670 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3671 | "Host: www.example.org:443\r\n" |
| 3672 | "Proxy-Connection: keep-alive\r\n" |
| 3673 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3674 | }; |
| 3675 | |
| 3676 | // The proxy responds to the connect with a 407, using a persistent |
| 3677 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3678 | MockRead data_reads1[] = { |
| 3679 | // No credentials. |
| 3680 | MockRead(ASYNC, 1, |
| 3681 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3682 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3683 | "Content-Length: 10\r\n\r\n"), |
| 3684 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3685 | |
| 3686 | // Wrong credentials (wrong password). |
| 3687 | MockRead(ASYNC, 4, |
| 3688 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3689 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3690 | "Content-Length: 10\r\n\r\n"), |
| 3691 | // No response body because the test stops reading here. |
| 3692 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3693 | }; |
| 3694 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3695 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3696 | data1.set_busy_before_sync_reads(true); |
| 3697 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3698 | |
| 3699 | TestCompletionCallback callback1; |
| 3700 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3701 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3702 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3703 | |
| 3704 | TestNetLogEntry::List entries; |
| 3705 | log.GetEntries(&entries); |
| 3706 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3707 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3708 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3709 | ExpectLogContainsSomewhere( |
| 3710 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3711 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3712 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3713 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3714 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3715 | ASSERT_TRUE(response); |
| 3716 | ASSERT_TRUE(response->headers); |
| 3717 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3718 | EXPECT_EQ(407, response->headers->response_code()); |
| 3719 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3720 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3721 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3722 | |
| 3723 | TestCompletionCallback callback2; |
| 3724 | |
| 3725 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3726 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3727 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3728 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3729 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3730 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3731 | ASSERT_TRUE(response); |
| 3732 | ASSERT_TRUE(response->headers); |
| 3733 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3734 | EXPECT_EQ(407, response->headers->response_code()); |
| 3735 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3736 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3737 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3738 | |
| 3739 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3740 | // out of scope. |
| 3741 | session->CloseAllConnections(); |
| 3742 | } |
| 3743 | } |
| 3744 | |
| 3745 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3746 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3747 | // the case the server sends extra data on the original socket, so it can't be |
| 3748 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3749 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3750 | HttpRequestInfo request; |
| 3751 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3752 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3753 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3754 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3755 | request.traffic_annotation = |
| 3756 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3757 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3758 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3759 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3760 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3761 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3762 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3763 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3764 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3765 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3766 | // Since we have proxy, should try to establish tunnel. |
| 3767 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3768 | MockWrite(ASYNC, 0, |
| 3769 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3770 | "Host: www.example.org:443\r\n" |
| 3771 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3772 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3773 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3774 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3775 | // extra data, so the socket cannot be reused. |
| 3776 | MockRead data_reads1[] = { |
| 3777 | // No credentials. |
| 3778 | MockRead(ASYNC, 1, |
| 3779 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3780 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3781 | "Content-Length: 10\r\n\r\n"), |
| 3782 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3783 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3784 | }; |
| 3785 | |
| 3786 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3787 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3788 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3789 | MockWrite(ASYNC, 0, |
| 3790 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3791 | "Host: www.example.org:443\r\n" |
| 3792 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3793 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3794 | |
| 3795 | MockWrite(ASYNC, 2, |
| 3796 | "GET / HTTP/1.1\r\n" |
| 3797 | "Host: www.example.org\r\n" |
| 3798 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3799 | }; |
| 3800 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3801 | MockRead data_reads2[] = { |
| 3802 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3803 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3804 | MockRead(ASYNC, 3, |
| 3805 | "HTTP/1.1 200 OK\r\n" |
| 3806 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3807 | "Content-Length: 5\r\n\r\n"), |
| 3808 | // No response body because the test stops reading here. |
| 3809 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3810 | }; |
| 3811 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3812 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3813 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3814 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3815 | SequencedSocketData data2(data_reads2, data_writes2); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3816 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3817 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3818 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3819 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3820 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3821 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3822 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3823 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3824 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3825 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3826 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3827 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3828 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3829 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3830 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3831 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3832 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3833 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3834 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3835 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3836 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3837 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3838 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3839 | ASSERT_TRUE(response); |
| 3840 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3841 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3842 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3843 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3844 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3845 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3846 | LoadTimingInfo load_timing_info; |
| 3847 | // CONNECT requests and responses are handled at the connect job level, so |
| 3848 | // the transaction does not yet have a connection. |
| 3849 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3850 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3851 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3852 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3853 | rv = |
| 3854 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3855 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3856 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3857 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3858 | EXPECT_EQ(200, response->headers->response_code()); |
| 3859 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3860 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3861 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3862 | // The password prompt info should not be set. |
| 3863 | EXPECT_FALSE(response->auth_challenge); |
| 3864 | |
| 3865 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3866 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3867 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3868 | |
| 3869 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3870 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3871 | } |
| 3872 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3873 | // Test the case a proxy closes a socket while the challenge body is being |
| 3874 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3875 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3876 | HttpRequestInfo request; |
| 3877 | request.method = "GET"; |
| 3878 | request.url = GURL("https://www.example.org/"); |
| 3879 | // Ensure that proxy authentication is attempted even |
| 3880 | // when the no authentication data flag is set. |
| 3881 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3882 | request.traffic_annotation = |
| 3883 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3884 | |
| 3885 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3886 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3887 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3888 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3889 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3890 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3891 | |
| 3892 | // Since we have proxy, should try to establish tunnel. |
| 3893 | MockWrite data_writes1[] = { |
| 3894 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3895 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3896 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3897 | }; |
| 3898 | |
| 3899 | // The proxy responds to the connect with a 407, using a persistent |
| 3900 | // connection. |
| 3901 | MockRead data_reads1[] = { |
| 3902 | // No credentials. |
| 3903 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3904 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3905 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3906 | // Server hands up in the middle of the body. |
| 3907 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3908 | }; |
| 3909 | |
| 3910 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3911 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3912 | // be issuing -- the final header line contains the credentials. |
| 3913 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3914 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3915 | "Proxy-Connection: keep-alive\r\n" |
| 3916 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3917 | |
| 3918 | MockWrite("GET / HTTP/1.1\r\n" |
| 3919 | "Host: www.example.org\r\n" |
| 3920 | "Connection: keep-alive\r\n\r\n"), |
| 3921 | }; |
| 3922 | |
| 3923 | MockRead data_reads2[] = { |
| 3924 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3925 | |
| 3926 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3927 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3928 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3929 | MockRead(SYNCHRONOUS, "hello"), |
| 3930 | }; |
| 3931 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3932 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3933 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3934 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3935 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3936 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3937 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3938 | |
| 3939 | TestCompletionCallback callback; |
| 3940 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3941 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3942 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3943 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3944 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3945 | ASSERT_TRUE(response); |
| 3946 | ASSERT_TRUE(response->headers); |
| 3947 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3948 | EXPECT_EQ(407, response->headers->response_code()); |
| 3949 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3950 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3951 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3952 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3953 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3954 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3955 | ASSERT_TRUE(response); |
| 3956 | ASSERT_TRUE(response->headers); |
| 3957 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3958 | EXPECT_EQ(200, response->headers->response_code()); |
| 3959 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3960 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3961 | EXPECT_EQ("hello", body); |
| 3962 | } |
| 3963 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3964 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3965 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3966 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3967 | HttpRequestInfo request; |
| 3968 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3969 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3970 | request.traffic_annotation = |
| 3971 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3972 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3973 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3974 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3975 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3976 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3977 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3978 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3979 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3980 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3981 | // Since we have proxy, should try to establish tunnel. |
| 3982 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3983 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3984 | "Host: www.example.org:443\r\n" |
| 3985 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3986 | }; |
| 3987 | |
| 3988 | // The proxy responds to the connect with a 407. |
| 3989 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3990 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3991 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3992 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3993 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3994 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3995 | }; |
| 3996 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3997 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3998 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3999 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4000 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4001 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4002 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4003 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4004 | |
| 4005 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4006 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4007 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4008 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4009 | ASSERT_TRUE(response); |
| 4010 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4011 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4012 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 4013 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4014 | |
| 4015 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4016 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4017 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 4018 | |
| 4019 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 4020 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 4021 | } |
| 4022 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4023 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 4024 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4025 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4026 | HttpRequestInfo request; |
| 4027 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4028 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4029 | request.traffic_annotation = |
| 4030 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4031 | |
| 4032 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4033 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4034 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4035 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4036 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4037 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4038 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4039 | |
| 4040 | // Since we have proxy, should try to establish tunnel. |
| 4041 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4042 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4043 | "Host: www.example.org:443\r\n" |
| 4044 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4045 | }; |
| 4046 | |
| 4047 | // The proxy responds to the connect with a 407. |
| 4048 | MockRead data_reads[] = { |
| 4049 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4050 | MockRead("X-Foo: bar\r\n"), |
| 4051 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 4052 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4053 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 4054 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4055 | }; |
| 4056 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4057 | StaticSocketDataProvider data(data_reads, data_writes); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4058 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 4059 | |
| 4060 | TestCompletionCallback callback; |
| 4061 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4062 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4063 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4064 | |
| 4065 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4066 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4067 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4068 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4069 | ASSERT_TRUE(response); |
| 4070 | ASSERT_TRUE(response->headers); |
| 4071 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4072 | EXPECT_EQ(407, response->headers->response_code()); |
| 4073 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4074 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 4075 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 4076 | |
| 4077 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4078 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4079 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 4080 | |
| 4081 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 4082 | session->CloseAllConnections(); |
| 4083 | } |
| 4084 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4085 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 4086 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4087 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4088 | HttpRequestInfo request; |
| 4089 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4090 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4091 | request.traffic_annotation = |
| 4092 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4093 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4094 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4095 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4096 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4097 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4098 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4099 | MockWrite( |
| 4100 | "GET / HTTP/1.1\r\n" |
| 4101 | "Host: www.example.org\r\n" |
| 4102 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4103 | }; |
| 4104 | |
| 4105 | MockRead data_reads1[] = { |
| 4106 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 4107 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4108 | // Large content-length -- won't matter, as connection will be reset. |
| 4109 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4110 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4111 | }; |
| 4112 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4113 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4114 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4115 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4116 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4117 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4118 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4119 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4120 | |
| 4121 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4122 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 4123 | } |
| 4124 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4125 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 4126 | // through a non-authenticating proxy. The request should fail with |
| 4127 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 4128 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 4129 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 4130 | // response came from the proxy or the server, so it is treated as if the proxy |
| 4131 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4132 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4133 | HttpRequestInfo request; |
| 4134 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4135 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4136 | request.traffic_annotation = |
| 4137 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4138 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4139 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4140 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4141 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4142 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4143 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4144 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4145 | // Since we have proxy, should try to establish tunnel. |
| 4146 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4147 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4148 | "Host: www.example.org:443\r\n" |
| 4149 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4150 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4151 | MockWrite("GET / HTTP/1.1\r\n" |
| 4152 | "Host: www.example.org\r\n" |
| 4153 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4154 | }; |
| 4155 | |
| 4156 | MockRead data_reads1[] = { |
| 4157 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4158 | |
| 4159 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 4160 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 4161 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4162 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4163 | }; |
| 4164 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4165 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4166 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4167 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4168 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4169 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4170 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4171 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4172 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4173 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4174 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4175 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4176 | |
| 4177 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4178 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 4179 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4180 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4181 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4182 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 4183 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4184 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 4185 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 4186 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 4187 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 4188 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4189 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4190 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4191 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4192 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4193 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 4194 | HttpRequestInfo request; |
| 4195 | request.method = "GET"; |
| 4196 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4197 | request.traffic_annotation = |
| 4198 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4199 | |
| 4200 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4201 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4202 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4203 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4204 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4205 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4206 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4207 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4208 | mock_handler->set_allows_default_credentials(true); |
| 4209 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4210 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4211 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4212 | |
| 4213 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4214 | NetLog net_log; |
| 4215 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4216 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4217 | |
| 4218 | // Since we have proxy, should try to establish tunnel. |
| 4219 | MockWrite data_writes1[] = { |
| 4220 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4221 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4222 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4223 | }; |
| 4224 | |
| 4225 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4226 | // connection. |
| 4227 | MockRead data_reads1[] = { |
| 4228 | // No credentials. |
| 4229 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4230 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4231 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4232 | }; |
| 4233 | |
| 4234 | // Since the first connection couldn't be reused, need to establish another |
| 4235 | // once given credentials. |
| 4236 | MockWrite data_writes2[] = { |
| 4237 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4238 | // be issuing -- the final header line contains the credentials. |
| 4239 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4240 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4241 | "Proxy-Connection: keep-alive\r\n" |
| 4242 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4243 | |
| 4244 | MockWrite("GET / HTTP/1.1\r\n" |
| 4245 | "Host: www.example.org\r\n" |
| 4246 | "Connection: keep-alive\r\n\r\n"), |
| 4247 | }; |
| 4248 | |
| 4249 | MockRead data_reads2[] = { |
| 4250 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4251 | |
| 4252 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4253 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4254 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4255 | MockRead(SYNCHRONOUS, "hello"), |
| 4256 | }; |
| 4257 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4258 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4259 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4260 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4261 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4262 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4263 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4264 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4265 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4266 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4267 | |
| 4268 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4269 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
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 | |
| 4272 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4273 | ASSERT_TRUE(response); |
| 4274 | ASSERT_TRUE(response->headers); |
| 4275 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4276 | EXPECT_EQ(407, response->headers->response_code()); |
| 4277 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4278 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4279 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4280 | |
| 4281 | LoadTimingInfo load_timing_info; |
| 4282 | // CONNECT requests and responses are handled at the connect job level, so |
| 4283 | // the transaction does not yet have a connection. |
| 4284 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4285 | |
| 4286 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4287 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4288 | response = trans->GetResponseInfo(); |
| 4289 | ASSERT_TRUE(response); |
| 4290 | ASSERT_TRUE(response->headers); |
| 4291 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4292 | EXPECT_EQ(200, response->headers->response_code()); |
| 4293 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4294 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4295 | |
| 4296 | // The password prompt info should not be set. |
| 4297 | EXPECT_FALSE(response->auth_challenge); |
| 4298 | |
| 4299 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4300 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4301 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4302 | |
| 4303 | trans.reset(); |
| 4304 | session->CloseAllConnections(); |
| 4305 | } |
| 4306 | |
| 4307 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4308 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4309 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4310 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4311 | HttpRequestInfo request; |
| 4312 | request.method = "GET"; |
| 4313 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4314 | request.traffic_annotation = |
| 4315 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4316 | |
| 4317 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4318 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4319 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4320 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4321 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4322 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4323 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4324 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4325 | mock_handler->set_allows_default_credentials(true); |
| 4326 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4327 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4328 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4329 | |
| 4330 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4331 | NetLog net_log; |
| 4332 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4333 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4334 | |
| 4335 | // Should try to establish tunnel. |
| 4336 | MockWrite data_writes1[] = { |
| 4337 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4338 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4339 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4340 | |
| 4341 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4342 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4343 | "Proxy-Connection: keep-alive\r\n" |
| 4344 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4345 | }; |
| 4346 | |
| 4347 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4348 | // connection. |
| 4349 | MockRead data_reads1[] = { |
| 4350 | // No credentials. |
| 4351 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4352 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4353 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4354 | }; |
| 4355 | |
| 4356 | // Since the first connection was closed, need to establish another once given |
| 4357 | // credentials. |
| 4358 | MockWrite data_writes2[] = { |
| 4359 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4360 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4361 | "Proxy-Connection: keep-alive\r\n" |
| 4362 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4363 | |
| 4364 | MockWrite("GET / HTTP/1.1\r\n" |
| 4365 | "Host: www.example.org\r\n" |
| 4366 | "Connection: keep-alive\r\n\r\n"), |
| 4367 | }; |
| 4368 | |
| 4369 | MockRead data_reads2[] = { |
| 4370 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4371 | |
| 4372 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4373 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4374 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4375 | MockRead(SYNCHRONOUS, "hello"), |
| 4376 | }; |
| 4377 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4378 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4379 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4380 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4381 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4382 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4383 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4384 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4385 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4386 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4387 | |
| 4388 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4389 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
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 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4393 | ASSERT_TRUE(response); |
| 4394 | ASSERT_TRUE(response->headers); |
| 4395 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4396 | EXPECT_EQ(407, response->headers->response_code()); |
| 4397 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4398 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4399 | EXPECT_FALSE(response->auth_challenge); |
| 4400 | |
| 4401 | LoadTimingInfo load_timing_info; |
| 4402 | // CONNECT requests and responses are handled at the connect job level, so |
| 4403 | // the transaction does not yet have a connection. |
| 4404 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4405 | |
| 4406 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4407 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4408 | |
| 4409 | response = trans->GetResponseInfo(); |
| 4410 | ASSERT_TRUE(response); |
| 4411 | ASSERT_TRUE(response->headers); |
| 4412 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4413 | EXPECT_EQ(200, response->headers->response_code()); |
| 4414 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4415 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4416 | |
| 4417 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4418 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4419 | |
| 4420 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4421 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4422 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4423 | |
| 4424 | trans.reset(); |
| 4425 | session->CloseAllConnections(); |
| 4426 | } |
| 4427 | |
| 4428 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4429 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4430 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4431 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4432 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4433 | HttpRequestInfo request; |
| 4434 | request.method = "GET"; |
| 4435 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4436 | request.traffic_annotation = |
| 4437 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4438 | |
| 4439 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4440 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4441 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4442 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4443 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4444 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4445 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4446 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4447 | mock_handler->set_allows_default_credentials(true); |
| 4448 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4449 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4450 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4451 | |
| 4452 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4453 | NetLog net_log; |
| 4454 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4455 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4456 | |
| 4457 | // Should try to establish tunnel. |
| 4458 | MockWrite data_writes1[] = { |
| 4459 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4460 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4461 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4462 | |
| 4463 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4464 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4465 | "Proxy-Connection: keep-alive\r\n" |
| 4466 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4467 | }; |
| 4468 | |
| 4469 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4470 | // second request is sent. |
| 4471 | MockRead data_reads1[] = { |
| 4472 | // No credentials. |
| 4473 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4474 | MockRead("Content-Length: 0\r\n"), |
| 4475 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4476 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4477 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4478 | }; |
| 4479 | |
| 4480 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4481 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4482 | // request. |
| 4483 | MockWrite data_writes2[] = { |
| 4484 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4485 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4486 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4487 | }; |
| 4488 | |
| 4489 | // The proxy, having had more than enough of us, just hangs up. |
| 4490 | MockRead data_reads2[] = { |
| 4491 | // No credentials. |
| 4492 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4493 | }; |
| 4494 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4495 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4496 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4497 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4498 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4499 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4500 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4501 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4502 | |
| 4503 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4504 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4505 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4506 | |
| 4507 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4508 | ASSERT_TRUE(response); |
| 4509 | ASSERT_TRUE(response->headers); |
| 4510 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4511 | EXPECT_EQ(407, response->headers->response_code()); |
| 4512 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4513 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4514 | EXPECT_FALSE(response->auth_challenge); |
| 4515 | |
| 4516 | LoadTimingInfo load_timing_info; |
| 4517 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4518 | |
| 4519 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4520 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4521 | |
| 4522 | trans.reset(); |
| 4523 | session->CloseAllConnections(); |
| 4524 | } |
| 4525 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4526 | // This test exercises an odd edge case where the proxy closes the connection |
| 4527 | // after the authentication handshake is complete. Presumably this technique is |
| 4528 | // used in lieu of returning a 403 or 5xx status code when the authentication |
| 4529 | // succeeds, but the user is not authorized to connect to the destination |
| 4530 | // server. There's no standard for what a proxy should do to indicate a blocked |
| 4531 | // site. |
| 4532 | TEST_F(HttpNetworkTransactionTest, |
| 4533 | AuthAllowsDefaultCredentialsTunnelConnectionClosesBeforeBody) { |
| 4534 | HttpRequestInfo request; |
| 4535 | request.method = "GET"; |
| 4536 | request.url = GURL("https://www.example.org/"); |
| 4537 | request.traffic_annotation = |
| 4538 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4539 | |
| 4540 | // Configure against proxy server "myproxy:70". |
| 4541 | session_deps_.proxy_resolution_service = |
| 4542 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4543 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 4544 | |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 4545 | // When TLS 1.3 is enabled, spurious connections are made as part of the SSL |
| 4546 | // version interference probes. |
| 4547 | // TODO(crbug.com/906668): Correctly handle version interference probes to |
| 4548 | // test TLS 1.3. |
| 4549 | SSLConfig config; |
| 4550 | config.version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
| 4551 | session_deps_.ssl_config_service = |
| 4552 | std::make_unique<TestSSLConfigService>(config); |
| 4553 | |
Asanka Herath | bc3f8f6 | 2018-11-16 23:08:30 | [diff] [blame] | 4554 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
| 4555 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4556 | |
| 4557 | // Create two mock AuthHandlers. This is because the transaction gets retried |
| 4558 | // after the first ERR_CONNECTION_CLOSED since it's ambiguous whether there |
| 4559 | // was a real network error. |
| 4560 | // |
| 4561 | // The handlers support both default and explicit credentials. The retry |
| 4562 | // mentioned above should be able to reuse the default identity. Thus there |
| 4563 | // should never be a need to prompt for explicit credentials. |
| 4564 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4565 | mock_handler->set_allows_default_credentials(true); |
| 4566 | mock_handler->set_allows_explicit_credentials(true); |
| 4567 | mock_handler->set_connection_based(true); |
| 4568 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4569 | HttpAuth::AUTH_PROXY); |
| 4570 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
| 4571 | mock_handler->set_allows_default_credentials(true); |
| 4572 | mock_handler->set_allows_explicit_credentials(true); |
| 4573 | mock_handler->set_connection_based(true); |
| 4574 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4575 | HttpAuth::AUTH_PROXY); |
| 4576 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4577 | |
| 4578 | NetLog net_log; |
| 4579 | session_deps_.net_log = &net_log; |
| 4580 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4581 | |
| 4582 | // Data for both sockets. |
| 4583 | // |
| 4584 | // Writes are for the tunnel establishment attempts and the |
| 4585 | // authentication handshake. |
| 4586 | MockWrite data_writes1[] = { |
| 4587 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4588 | "Host: www.example.org:443\r\n" |
| 4589 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4590 | |
| 4591 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4592 | "Host: www.example.org:443\r\n" |
| 4593 | "Proxy-Connection: keep-alive\r\n" |
| 4594 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4595 | |
| 4596 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4597 | "Host: www.example.org:443\r\n" |
| 4598 | "Proxy-Connection: keep-alive\r\n" |
| 4599 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4600 | }; |
| 4601 | |
| 4602 | // The server side of the authentication handshake. Note that the response to |
| 4603 | // the final CONNECT request is ERR_CONNECTION_CLOSED. |
| 4604 | MockRead data_reads1[] = { |
| 4605 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4606 | MockRead("Content-Length: 0\r\n"), |
| 4607 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4608 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4609 | |
| 4610 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4611 | MockRead("Content-Length: 0\r\n"), |
| 4612 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4613 | MockRead("Proxy-Authenticate: Mock foo\r\n\r\n"), |
| 4614 | |
| 4615 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4616 | }; |
| 4617 | |
| 4618 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 4619 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4620 | |
| 4621 | // The second socket is for the reconnection attempt. Data is identical to the |
| 4622 | // first attempt. |
| 4623 | StaticSocketDataProvider data2(data_reads1, data_writes1); |
| 4624 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4625 | |
| 4626 | auto trans = |
| 4627 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 4628 | |
| 4629 | TestCompletionCallback callback; |
| 4630 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4631 | |
| 4632 | // Two rounds per handshake. After one retry, the error is propagated up the |
| 4633 | // stack. |
| 4634 | for (int i = 0; i < 4; ++i) { |
| 4635 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4636 | |
| 4637 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4638 | ASSERT_TRUE(response); |
| 4639 | ASSERT_TRUE(response->headers); |
| 4640 | EXPECT_EQ(407, response->headers->response_code()); |
| 4641 | ASSERT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4642 | |
| 4643 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4644 | } |
| 4645 | |
| 4646 | // One shall be the number thou shalt retry, and the number of the retrying |
| 4647 | // shall be one. Two shalt thou not retry, neither retry thou zero, excepting |
| 4648 | // that thou then proceed to one. Three is right out. Once the number one, |
| 4649 | // being the first number, be reached, then lobbest thou thy |
| 4650 | // ERR_CONNECTION_CLOSED towards they network transaction, who shall snuff it. |
| 4651 | EXPECT_EQ(ERR_CONNECTION_CLOSED, callback.GetResult(rv)); |
| 4652 | |
| 4653 | trans.reset(); |
| 4654 | session->CloseAllConnections(); |
| 4655 | } |
| 4656 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4657 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4658 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4659 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4660 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4661 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4662 | HttpRequestInfo request; |
| 4663 | request.method = "GET"; |
| 4664 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4665 | request.traffic_annotation = |
| 4666 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4667 | |
| 4668 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4669 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4670 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4671 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4672 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4673 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4674 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4675 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4676 | mock_handler->set_allows_default_credentials(true); |
| 4677 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4678 | HttpAuth::AUTH_PROXY); |
| 4679 | // Add another handler for the second challenge. It supports default |
| 4680 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4681 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4682 | mock_handler->set_allows_default_credentials(true); |
| 4683 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4684 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4685 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4686 | |
| 4687 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4688 | NetLog net_log; |
| 4689 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4690 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4691 | |
| 4692 | // Should try to establish tunnel. |
| 4693 | MockWrite data_writes1[] = { |
| 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\r\n"), |
| 4697 | }; |
| 4698 | |
| 4699 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4700 | // connection. |
| 4701 | MockRead data_reads1[] = { |
| 4702 | // No credentials. |
| 4703 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4704 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4705 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4706 | }; |
| 4707 | |
| 4708 | // Since the first connection was closed, need to establish another once given |
| 4709 | // credentials. |
| 4710 | MockWrite data_writes2[] = { |
| 4711 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4712 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4713 | "Proxy-Connection: keep-alive\r\n" |
| 4714 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4715 | }; |
| 4716 | |
| 4717 | MockRead data_reads2[] = { |
| 4718 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4719 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4720 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4721 | }; |
| 4722 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4723 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4724 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4725 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4726 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4727 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4728 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4729 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4730 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4731 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4732 | |
| 4733 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4734 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4735 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4736 | |
| 4737 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4738 | ASSERT_TRUE(response); |
| 4739 | ASSERT_TRUE(response->headers); |
| 4740 | EXPECT_EQ(407, response->headers->response_code()); |
| 4741 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4742 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4743 | EXPECT_FALSE(response->auth_challenge); |
| 4744 | |
| 4745 | LoadTimingInfo load_timing_info; |
| 4746 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4747 | |
| 4748 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4749 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4750 | response = trans->GetResponseInfo(); |
| 4751 | ASSERT_TRUE(response); |
| 4752 | ASSERT_TRUE(response->headers); |
| 4753 | EXPECT_EQ(407, response->headers->response_code()); |
| 4754 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4755 | EXPECT_TRUE(response->auth_challenge); |
| 4756 | |
| 4757 | trans.reset(); |
| 4758 | session->CloseAllConnections(); |
| 4759 | } |
| 4760 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4761 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4762 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4763 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4764 | // authentication handshake can continue with the same scheme but with a |
| 4765 | // different identity. |
| 4766 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4767 | HttpRequestInfo request; |
| 4768 | request.method = "GET"; |
| 4769 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4770 | request.traffic_annotation = |
| 4771 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4772 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4773 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4774 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4775 | |
| 4776 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4777 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4778 | mock_handler->set_allows_default_credentials(true); |
| 4779 | mock_handler->set_allows_explicit_credentials(true); |
| 4780 | mock_handler->set_connection_based(true); |
| 4781 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4782 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4783 | HttpAuth::AUTH_SERVER); |
| 4784 | |
| 4785 | // Add another handler for the second challenge. It supports default |
| 4786 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4787 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4788 | mock_handler->set_allows_default_credentials(true); |
| 4789 | mock_handler->set_allows_explicit_credentials(true); |
| 4790 | mock_handler->set_connection_based(true); |
| 4791 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4792 | HttpAuth::AUTH_SERVER); |
| 4793 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4794 | |
| 4795 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4796 | |
| 4797 | MockWrite data_writes1[] = { |
| 4798 | MockWrite("GET / HTTP/1.1\r\n" |
| 4799 | "Host: www.example.org\r\n" |
| 4800 | "Connection: keep-alive\r\n\r\n"), |
| 4801 | }; |
| 4802 | |
| 4803 | MockRead data_reads1[] = { |
| 4804 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4805 | "WWW-Authenticate: Mock\r\n" |
| 4806 | "Connection: keep-alive\r\n\r\n"), |
| 4807 | }; |
| 4808 | |
| 4809 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4810 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4811 | // transaction procceds without an authorization header. |
| 4812 | MockWrite data_writes2[] = { |
| 4813 | MockWrite("GET / HTTP/1.1\r\n" |
| 4814 | "Host: www.example.org\r\n" |
| 4815 | "Connection: keep-alive\r\n\r\n"), |
| 4816 | }; |
| 4817 | |
| 4818 | MockRead data_reads2[] = { |
| 4819 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4820 | "WWW-Authenticate: Mock\r\n" |
| 4821 | "Connection: keep-alive\r\n\r\n"), |
| 4822 | }; |
| 4823 | |
| 4824 | MockWrite data_writes3[] = { |
| 4825 | MockWrite("GET / HTTP/1.1\r\n" |
| 4826 | "Host: www.example.org\r\n" |
| 4827 | "Connection: keep-alive\r\n" |
| 4828 | "Authorization: auth_token\r\n\r\n"), |
| 4829 | }; |
| 4830 | |
| 4831 | MockRead data_reads3[] = { |
| 4832 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4833 | "Content-Length: 5\r\n" |
| 4834 | "Content-Type: text/plain\r\n" |
| 4835 | "Connection: keep-alive\r\n\r\n" |
| 4836 | "Hello"), |
| 4837 | }; |
| 4838 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4839 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4840 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4841 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4842 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4843 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4844 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4845 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4846 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4847 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4848 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4849 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4850 | |
| 4851 | TestCompletionCallback callback; |
| 4852 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4853 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4854 | |
| 4855 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4856 | ASSERT_TRUE(response); |
| 4857 | ASSERT_TRUE(response->headers); |
| 4858 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4859 | |
| 4860 | // The following three tests assert that an authentication challenge was |
| 4861 | // received and that the stack is ready to respond to the challenge using |
| 4862 | // ambient credentials. |
| 4863 | EXPECT_EQ(401, response->headers->response_code()); |
| 4864 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4865 | EXPECT_FALSE(response->auth_challenge); |
| 4866 | |
| 4867 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4868 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4869 | response = trans->GetResponseInfo(); |
| 4870 | ASSERT_TRUE(response); |
| 4871 | ASSERT_TRUE(response->headers); |
| 4872 | |
| 4873 | // The following three tests assert that an authentication challenge was |
| 4874 | // received and that the stack needs explicit credentials before it is ready |
| 4875 | // to respond to the challenge. |
| 4876 | EXPECT_EQ(401, response->headers->response_code()); |
| 4877 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4878 | EXPECT_TRUE(response->auth_challenge); |
| 4879 | |
| 4880 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4881 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4882 | response = trans->GetResponseInfo(); |
| 4883 | ASSERT_TRUE(response); |
| 4884 | ASSERT_TRUE(response->headers); |
| 4885 | EXPECT_EQ(200, response->headers->response_code()); |
| 4886 | |
| 4887 | trans.reset(); |
| 4888 | session->CloseAllConnections(); |
| 4889 | } |
| 4890 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4891 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4892 | // schemes, based on the path of the URL being requests. |
| 4893 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4894 | public: |
| 4895 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4896 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4897 | |
| 4898 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4899 | |
| 4900 | static HostPortPair ProxyHostPortPair() { |
| 4901 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4902 | } |
| 4903 | |
| 4904 | // ProxyResolver implementation. |
| 4905 | int GetProxyForURL(const GURL& url, |
| 4906 | ProxyInfo* results, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4907 | CompletionOnceCallback callback, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4908 | std::unique_ptr<Request>* request, |
| 4909 | const NetLogWithSource& /*net_log*/) override { |
| 4910 | *results = ProxyInfo(); |
Ramin Halavati | 921731ea | 2018-03-16 08:24:57 | [diff] [blame] | 4911 | results->set_traffic_annotation( |
| 4912 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4913 | if (url.path() == "/socks4") { |
| 4914 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 4915 | return OK; |
| 4916 | } |
| 4917 | if (url.path() == "/socks5") { |
| 4918 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 4919 | return OK; |
| 4920 | } |
| 4921 | if (url.path() == "/http") { |
| 4922 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 4923 | return OK; |
| 4924 | } |
| 4925 | if (url.path() == "/https") { |
| 4926 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 4927 | return OK; |
| 4928 | } |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 4929 | if (url.path() == "/https_trusted") { |
| 4930 | results->UseProxyServer(ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 4931 | ProxyHostPortPair(), |
| 4932 | true /* is_trusted_proxy */)); |
| 4933 | return OK; |
| 4934 | } |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4935 | NOTREACHED(); |
| 4936 | return ERR_NOT_IMPLEMENTED; |
| 4937 | } |
| 4938 | |
| 4939 | private: |
| 4940 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 4941 | }; |
| 4942 | |
| 4943 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 4944 | : public ProxyResolverFactory { |
| 4945 | public: |
| 4946 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 4947 | : ProxyResolverFactory(false) {} |
| 4948 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4949 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 4950 | std::unique_ptr<ProxyResolver>* resolver, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4951 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4952 | std::unique_ptr<Request>* request) override { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4953 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 4954 | return OK; |
| 4955 | } |
| 4956 | |
| 4957 | private: |
| 4958 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 4959 | }; |
| 4960 | |
| 4961 | // 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] | 4962 | // same address, the connections are not grouped together. i.e., a request to |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4963 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 4964 | // request to foo.com using proxy.com as an HTTP proxy. |
| 4965 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4966 | session_deps_.proxy_resolution_service = |
| 4967 | std::make_unique<ProxyResolutionService>( |
| 4968 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 4969 | ProxyConfig::CreateAutoDetect(), TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 4970 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 4971 | nullptr); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4972 | |
| 4973 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4974 | |
| 4975 | MockWrite socks_writes[] = { |
| 4976 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 4977 | kSOCKS4OkRequestLocalHostPort80Length), |
| 4978 | MockWrite(SYNCHRONOUS, |
| 4979 | "GET /socks4 HTTP/1.1\r\n" |
| 4980 | "Host: test\r\n" |
| 4981 | "Connection: keep-alive\r\n\r\n"), |
| 4982 | }; |
| 4983 | MockRead socks_reads[] = { |
| 4984 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 4985 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4986 | "Connection: keep-alive\r\n" |
| 4987 | "Content-Length: 15\r\n\r\n" |
| 4988 | "SOCKS4 Response"), |
| 4989 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4990 | StaticSocketDataProvider socks_data(socks_reads, socks_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4991 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 4992 | |
| 4993 | const char kSOCKS5Request[] = { |
| 4994 | 0x05, // Version |
| 4995 | 0x01, // Command (CONNECT) |
| 4996 | 0x00, // Reserved |
| 4997 | 0x03, // Address type (DOMAINNAME) |
| 4998 | 0x04, // Length of domain (4) |
| 4999 | 't', 'e', 's', 't', // Domain string |
| 5000 | 0x00, 0x50, // 16-bit port (80) |
| 5001 | }; |
| 5002 | MockWrite socks5_writes[] = { |
| 5003 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5004 | MockWrite(ASYNC, kSOCKS5Request, base::size(kSOCKS5Request)), |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5005 | MockWrite(SYNCHRONOUS, |
| 5006 | "GET /socks5 HTTP/1.1\r\n" |
| 5007 | "Host: test\r\n" |
| 5008 | "Connection: keep-alive\r\n\r\n"), |
| 5009 | }; |
| 5010 | MockRead socks5_reads[] = { |
| 5011 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 5012 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 5013 | MockRead("HTTP/1.0 200 OK\r\n" |
| 5014 | "Connection: keep-alive\r\n" |
| 5015 | "Content-Length: 15\r\n\r\n" |
| 5016 | "SOCKS5 Response"), |
| 5017 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5018 | StaticSocketDataProvider socks5_data(socks5_reads, socks5_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5019 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 5020 | |
| 5021 | MockWrite http_writes[] = { |
| 5022 | MockWrite(SYNCHRONOUS, |
| 5023 | "GET http://test/http HTTP/1.1\r\n" |
| 5024 | "Host: test\r\n" |
| 5025 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5026 | }; |
| 5027 | MockRead http_reads[] = { |
| 5028 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5029 | "Proxy-Connection: keep-alive\r\n" |
| 5030 | "Content-Length: 13\r\n\r\n" |
| 5031 | "HTTP Response"), |
| 5032 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5033 | StaticSocketDataProvider http_data(http_reads, http_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5034 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 5035 | |
| 5036 | MockWrite https_writes[] = { |
| 5037 | MockWrite(SYNCHRONOUS, |
| 5038 | "GET http://test/https HTTP/1.1\r\n" |
| 5039 | "Host: test\r\n" |
| 5040 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5041 | }; |
| 5042 | MockRead https_reads[] = { |
| 5043 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5044 | "Proxy-Connection: keep-alive\r\n" |
| 5045 | "Content-Length: 14\r\n\r\n" |
| 5046 | "HTTPS Response"), |
| 5047 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5048 | StaticSocketDataProvider https_data(https_reads, https_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5049 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 5050 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 5051 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5052 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5053 | MockWrite https_trusted_writes[] = { |
| 5054 | MockWrite(SYNCHRONOUS, |
| 5055 | "GET http://test/https_trusted HTTP/1.1\r\n" |
| 5056 | "Host: test\r\n" |
| 5057 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5058 | }; |
| 5059 | MockRead https_trusted_reads[] = { |
| 5060 | MockRead("HTTP/1.1 200 OK\r\n" |
| 5061 | "Proxy-Connection: keep-alive\r\n" |
| 5062 | "Content-Length: 22\r\n\r\n" |
| 5063 | "HTTPS Trusted Response"), |
| 5064 | }; |
| 5065 | StaticSocketDataProvider trusted_https_data(https_trusted_reads, |
| 5066 | https_trusted_writes); |
| 5067 | session_deps_.socket_factory->AddSocketDataProvider(&trusted_https_data); |
| 5068 | SSLSocketDataProvider ssl2(SYNCHRONOUS, OK); |
| 5069 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 5070 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5071 | struct TestCase { |
| 5072 | GURL url; |
| 5073 | std::string expected_response; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5074 | // 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] | 5075 | // after the test. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5076 | int expected_idle_socks4_sockets; |
| 5077 | int expected_idle_socks5_sockets; |
| 5078 | // How many idle sockets there should be in the HTTP/HTTPS proxy socket |
| 5079 | // pools after the test. |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5080 | int expected_idle_http_sockets; |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5081 | int expected_idle_https_sockets; |
| 5082 | // How many idle sockets there should be in the HTTPS proxy socket pool with |
| 5083 | // the ProxyServer's |is_trusted_proxy| bit set after the test. |
| 5084 | int expected_idle_trusted_https_sockets; |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5085 | } const kTestCases[] = { |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5086 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0, 0, 0, 0}, |
| 5087 | {GURL("http://test/socks5"), "SOCKS5 Response", 1, 1, 0, 0, 0}, |
| 5088 | {GURL("http://test/http"), "HTTP Response", 1, 1, 1, 0, 0}, |
| 5089 | {GURL("http://test/https"), "HTTPS Response", 1, 1, 1, 1, 0}, |
| 5090 | {GURL("http://test/https_trusted"), "HTTPS Trusted Response", 1, 1, 1, 1, |
| 5091 | 1}, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5092 | }; |
| 5093 | |
| 5094 | for (const auto& test_case : kTestCases) { |
| 5095 | HttpRequestInfo request; |
| 5096 | request.method = "GET"; |
| 5097 | request.url = test_case.url; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5098 | request.traffic_annotation = |
| 5099 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5100 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 5101 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 5102 | session.get()); |
| 5103 | TestCompletionCallback callback; |
| 5104 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 5105 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5106 | |
| 5107 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 5108 | ASSERT_TRUE(response); |
| 5109 | ASSERT_TRUE(response->headers); |
| 5110 | EXPECT_EQ(200, response->headers->response_code()); |
| 5111 | std::string response_data; |
| 5112 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 5113 | EXPECT_EQ(test_case.expected_response, response_data); |
| 5114 | |
| 5115 | // Return the socket to the socket pool, so can make sure it's not used for |
| 5116 | // the next requests. |
| 5117 | trans.reset(); |
| 5118 | base::RunLoop().RunUntilIdle(); |
| 5119 | |
| 5120 | // Check the number of idle sockets in the pool, to make sure that used |
| 5121 | // sockets are indeed being returned to the socket pool. If each request |
| 5122 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 5123 | // pass. |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 5124 | EXPECT_EQ(test_case.expected_idle_socks4_sockets, |
| 5125 | session |
| 5126 | ->GetSocketPoolForSOCKSProxy( |
| 5127 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5128 | ProxyServer(ProxyServer::SCHEME_SOCKS4, |
| 5129 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5130 | ProxyHostPortPair())) |
| 5131 | ->IdleSocketCount()); |
| 5132 | EXPECT_EQ(test_case.expected_idle_socks5_sockets, |
| 5133 | session |
| 5134 | ->GetSocketPoolForSOCKSProxy( |
| 5135 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5136 | ProxyServer(ProxyServer::SCHEME_SOCKS5, |
| 5137 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5138 | ProxyHostPortPair())) |
| 5139 | ->IdleSocketCount()); |
| 5140 | EXPECT_EQ(test_case.expected_idle_http_sockets, |
| 5141 | session |
| 5142 | ->GetSocketPoolForHTTPLikeProxy( |
| 5143 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5144 | ProxyServer(ProxyServer::SCHEME_HTTP, |
| 5145 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5146 | ProxyHostPortPair())) |
| 5147 | ->IdleSocketCount()); |
| 5148 | EXPECT_EQ(test_case.expected_idle_https_sockets, |
| 5149 | session |
| 5150 | ->GetSocketPoolForHTTPLikeProxy( |
| 5151 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5152 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5153 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5154 | ProxyHostPortPair())) |
| 5155 | ->IdleSocketCount()); |
| 5156 | EXPECT_EQ(test_case.expected_idle_trusted_https_sockets, |
| 5157 | session |
| 5158 | ->GetSocketPoolForHTTPLikeProxy( |
| 5159 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 5160 | ProxyServer(ProxyServer::SCHEME_HTTPS, |
| 5161 | SameProxyWithDifferentSchemesProxyResolver:: |
| 5162 | ProxyHostPortPair(), |
| 5163 | true /* is_trusted_proxy */)) |
| 5164 | ->IdleSocketCount()); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 5165 | } |
| 5166 | } |
| 5167 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5168 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5169 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5170 | HttpRequestInfo request1; |
| 5171 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5172 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5173 | request1.traffic_annotation = |
| 5174 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5175 | |
| 5176 | HttpRequestInfo request2; |
| 5177 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5178 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5179 | request2.traffic_annotation = |
| 5180 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5181 | |
| 5182 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5183 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5184 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5185 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5186 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5187 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5188 | |
| 5189 | // Since we have proxy, should try to establish tunnel. |
| 5190 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5191 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5192 | "Host: www.example.org:443\r\n" |
| 5193 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5194 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5195 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5196 | "Host: www.example.org\r\n" |
| 5197 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5198 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5199 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5200 | "Host: www.example.org\r\n" |
| 5201 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5202 | }; |
| 5203 | |
| 5204 | // The proxy responds to the connect with a 407, using a persistent |
| 5205 | // connection. |
| 5206 | MockRead data_reads1[] = { |
| 5207 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5208 | |
| 5209 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5210 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5211 | MockRead(SYNCHRONOUS, "1"), |
| 5212 | |
| 5213 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5214 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5215 | MockRead(SYNCHRONOUS, "22"), |
| 5216 | }; |
| 5217 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5218 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5219 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5220 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5221 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5222 | |
| 5223 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5224 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5225 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5226 | |
| 5227 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5228 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5229 | |
| 5230 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5231 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5232 | |
| 5233 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5234 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5235 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5236 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5237 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5238 | |
| 5239 | LoadTimingInfo load_timing_info1; |
| 5240 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5241 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5242 | |
| 5243 | trans1.reset(); |
| 5244 | |
| 5245 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5246 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5247 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5248 | |
| 5249 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5250 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5251 | |
| 5252 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5253 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5254 | |
| 5255 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5256 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5257 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5258 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5259 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5260 | |
| 5261 | LoadTimingInfo load_timing_info2; |
| 5262 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5263 | TestLoadTimingReused(load_timing_info2); |
| 5264 | |
| 5265 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5266 | |
| 5267 | trans2.reset(); |
| 5268 | session->CloseAllConnections(); |
| 5269 | } |
| 5270 | |
| 5271 | // 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] | 5272 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5273 | HttpRequestInfo request1; |
| 5274 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5275 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5276 | request1.traffic_annotation = |
| 5277 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5278 | |
| 5279 | HttpRequestInfo request2; |
| 5280 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5281 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5282 | request2.traffic_annotation = |
| 5283 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5284 | |
| 5285 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 5286 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5287 | ProxyResolutionService::CreateFixedFromPacResult( |
| 5288 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5289 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5290 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5291 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5292 | |
| 5293 | // Since we have proxy, should try to establish tunnel. |
| 5294 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5295 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5296 | "Host: www.example.org:443\r\n" |
| 5297 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5298 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5299 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 5300 | "Host: www.example.org\r\n" |
| 5301 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5302 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5303 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 5304 | "Host: www.example.org\r\n" |
| 5305 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5306 | }; |
| 5307 | |
| 5308 | // The proxy responds to the connect with a 407, using a persistent |
| 5309 | // connection. |
| 5310 | MockRead data_reads1[] = { |
| 5311 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 5312 | |
| 5313 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5314 | MockRead("Content-Length: 1\r\n\r\n"), |
| 5315 | MockRead(SYNCHRONOUS, "1"), |
| 5316 | |
| 5317 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5318 | MockRead("Content-Length: 2\r\n\r\n"), |
| 5319 | MockRead(SYNCHRONOUS, "22"), |
| 5320 | }; |
| 5321 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5322 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5323 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5324 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5325 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5326 | |
| 5327 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5328 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5329 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5330 | |
| 5331 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5332 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5333 | |
| 5334 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5335 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5336 | |
| 5337 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5338 | ASSERT_TRUE(response1); |
| 5339 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5340 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 5341 | |
| 5342 | LoadTimingInfo load_timing_info1; |
| 5343 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 5344 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 5345 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 5346 | |
| 5347 | trans1.reset(); |
| 5348 | |
| 5349 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5350 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5351 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5352 | |
| 5353 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5354 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5355 | |
| 5356 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5357 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5358 | |
| 5359 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5360 | ASSERT_TRUE(response2); |
| 5361 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 5362 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 5363 | |
| 5364 | LoadTimingInfo load_timing_info2; |
| 5365 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5366 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 5367 | |
| 5368 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 5369 | |
| 5370 | trans2.reset(); |
| 5371 | session->CloseAllConnections(); |
| 5372 | } |
| 5373 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5374 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5375 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5376 | HttpRequestInfo request; |
| 5377 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5378 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5379 | request.traffic_annotation = |
| 5380 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5381 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5382 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5383 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5384 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5385 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5386 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5387 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5388 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5389 | // Since we have proxy, should use full url |
| 5390 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5391 | MockWrite( |
| 5392 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 5393 | "Host: www.example.org\r\n" |
| 5394 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5395 | }; |
| 5396 | |
| 5397 | MockRead data_reads1[] = { |
| 5398 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5399 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5400 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5401 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5402 | }; |
| 5403 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5404 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5405 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5406 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5407 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5408 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5409 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5410 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5411 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5412 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5413 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5414 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5415 | |
| 5416 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5417 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5418 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5419 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5420 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5421 | TestLoadTimingNotReused(load_timing_info, |
| 5422 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5423 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5424 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5425 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5426 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5427 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5428 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5429 | EXPECT_EQ(200, response->headers->response_code()); |
| 5430 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5431 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5432 | |
| 5433 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5434 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5435 | } |
| 5436 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5437 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5438 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5439 | HttpRequestInfo request; |
| 5440 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5441 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5442 | request.traffic_annotation = |
| 5443 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5444 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5445 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5446 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5447 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5448 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5449 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5450 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5451 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5452 | // fetch http://www.example.org/ via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5453 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5454 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5455 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5456 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5457 | spdy::SpdySerializedFrame resp( |
| 5458 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 5459 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5460 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5461 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5462 | }; |
| 5463 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5464 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5465 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5466 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5467 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5468 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5469 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5470 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5471 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5472 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5473 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5474 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5475 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5476 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5477 | |
| 5478 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5479 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5480 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5481 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5482 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5483 | TestLoadTimingNotReused(load_timing_info, |
| 5484 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5485 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5486 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5487 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5488 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5489 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5490 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5491 | |
| 5492 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5493 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5494 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5495 | } |
| 5496 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5497 | // Verifies that a session which races and wins against the owning transaction |
| 5498 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5499 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5500 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5501 | HttpRequestInfo request; |
| 5502 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5503 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5504 | request.traffic_annotation = |
| 5505 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5506 | |
| 5507 | // Configure SPDY proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5508 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5509 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5510 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5511 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5512 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5513 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5514 | // Fetch http://www.example.org/ through the SPDY proxy. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5515 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5516 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5517 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5518 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5519 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 5520 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5521 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5522 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5523 | }; |
| 5524 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5525 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5526 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5527 | |
| 5528 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5529 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5530 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5531 | |
| 5532 | TestCompletionCallback callback1; |
| 5533 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5534 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5535 | |
| 5536 | // Stall the hostname resolution begun by the transaction. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5537 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5538 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5539 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5540 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5541 | |
| 5542 | // Race a session to the proxy, which completes first. |
| 5543 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 5544 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 5545 | PRIVACY_MODE_DISABLED, |
| 5546 | SpdySessionKey::IsProxySession::kTrue, SocketTag()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5547 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5548 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5549 | |
| 5550 | // Unstall the resolution begun by the transaction. |
| 5551 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5552 | session_deps_.host_resolver->ResolveAllPending(); |
| 5553 | |
| 5554 | EXPECT_FALSE(callback1.have_result()); |
| 5555 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5556 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5557 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5558 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5559 | ASSERT_TRUE(response); |
| 5560 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5561 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5562 | |
| 5563 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5564 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5565 | EXPECT_EQ(kUploadData, response_data); |
| 5566 | } |
| 5567 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5568 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5569 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5570 | HttpRequestInfo request; |
| 5571 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5572 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5573 | request.traffic_annotation = |
| 5574 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5575 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5576 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5577 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5578 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5579 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5580 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5581 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5582 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5583 | // The first request will be a bare GET, the second request will be a |
| 5584 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5585 | spdy_util_.set_default_url(request.url); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5586 | spdy::SpdySerializedFrame req_get( |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5587 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5588 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5589 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5590 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5591 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5592 | spdy::SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5593 | kExtraAuthorizationHeaders, base::size(kExtraAuthorizationHeaders) / 2, 3, |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5594 | LOWEST)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5595 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5596 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5597 | }; |
| 5598 | |
| 5599 | // The first response is a 407 proxy authentication challenge, and the second |
| 5600 | // response will be a 200 response since the second request includes a valid |
| 5601 | // Authorization header. |
| 5602 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5603 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5604 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5605 | spdy::SpdySerializedFrame resp_authentication( |
| 5606 | spdy_util_.ConstructSpdyReplyError( |
| 5607 | "407", kExtraAuthenticationHeaders, |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 5608 | base::size(kExtraAuthenticationHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5609 | spdy::SpdySerializedFrame body_authentication( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5610 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5611 | spdy::SpdySerializedFrame resp_data( |
| 5612 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 5613 | spdy::SpdySerializedFrame body_data( |
| 5614 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5615 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5616 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5617 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5618 | CreateMockRead(resp_data, 4), |
| 5619 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5620 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5621 | }; |
| 5622 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5623 | SequencedSocketData data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5624 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5625 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5626 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5627 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5628 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5629 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5630 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5631 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5632 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5633 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5634 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5635 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5636 | |
| 5637 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5638 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5639 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5640 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5641 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5642 | ASSERT_TRUE(response); |
| 5643 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5644 | EXPECT_EQ(407, response->headers->response_code()); |
| 5645 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5646 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5647 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5648 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5649 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5650 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5651 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5652 | |
| 5653 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5654 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5655 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5656 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5657 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5658 | ASSERT_TRUE(response_restart); |
| 5659 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5660 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5661 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5662 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5663 | } |
| 5664 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5665 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5666 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5667 | HttpRequestInfo request; |
| 5668 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5669 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5670 | request.traffic_annotation = |
| 5671 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5672 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5673 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5674 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5675 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5676 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5677 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5678 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5679 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5680 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5681 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5682 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5683 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5684 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5685 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5686 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5687 | const char get[] = |
| 5688 | "GET / HTTP/1.1\r\n" |
| 5689 | "Host: www.example.org\r\n" |
| 5690 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5691 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5692 | spdy_util_.ConstructSpdyDataFrame(1, get, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5693 | spdy::SpdySerializedFrame conn_resp( |
| 5694 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5695 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5696 | "Content-Length: 10\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5697 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5698 | spdy_util_.ConstructSpdyDataFrame(1, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5699 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5700 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5701 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5702 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5703 | |
| 5704 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5705 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5706 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5707 | }; |
| 5708 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5709 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5710 | CreateMockRead(conn_resp, 1, ASYNC), |
| 5711 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 5712 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 5713 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5714 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5715 | }; |
| 5716 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5717 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5718 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5719 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5720 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5721 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5722 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5723 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5724 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5725 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5726 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5727 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5728 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5729 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5730 | |
| 5731 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5732 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5733 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5734 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5735 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5736 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5737 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5738 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5739 | ASSERT_TRUE(response); |
| 5740 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5741 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5742 | |
| 5743 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5744 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5745 | EXPECT_EQ("1234567890", response_data); |
| 5746 | } |
| 5747 | |
| 5748 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5749 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5750 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5751 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5752 | HttpRequestInfo request; |
| 5753 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5754 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5755 | request.traffic_annotation = |
| 5756 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5757 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5758 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5759 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5760 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5761 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5762 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5763 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5764 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5765 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5766 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5767 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5768 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5769 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5770 | // fetch https://www.example.org/ via SPDY |
| 5771 | const char kMyUrl[] = "https://www.example.org/"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5772 | spdy::SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5773 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5774 | spdy::SpdySerializedFrame wrapped_get( |
| 5775 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 5776 | spdy::SpdySerializedFrame conn_resp( |
| 5777 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 5778 | spdy::SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5779 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5780 | spdy::SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5781 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5782 | spdy::SpdySerializedFrame body( |
| 5783 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5784 | spdy::SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5785 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5786 | spdy::SpdySerializedFrame window_update_get_resp( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5787 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5788 | spdy::SpdySerializedFrame window_update_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5789 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5790 | |
| 5791 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5792 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5793 | CreateMockWrite(window_update_get_resp, 6), |
| 5794 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5795 | }; |
| 5796 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5797 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5798 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5799 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5800 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5801 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5802 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5803 | }; |
| 5804 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5805 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5806 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5807 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5808 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5809 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5810 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5811 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5812 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5813 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5814 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5815 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5816 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5817 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5818 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5819 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5820 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5821 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5822 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5823 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5824 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5825 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5826 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5827 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5828 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5829 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5830 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5831 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5832 | ASSERT_TRUE(response); |
| 5833 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5834 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5835 | |
| 5836 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5837 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5838 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5839 | } |
| 5840 | |
| 5841 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5842 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5843 | HttpRequestInfo request; |
| 5844 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5845 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5846 | request.traffic_annotation = |
| 5847 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5848 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5849 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5850 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5851 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5852 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5853 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5854 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5855 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5856 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5857 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5858 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5859 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5860 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5861 | spdy::SpdySerializedFrame get( |
| 5862 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5863 | |
| 5864 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5865 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5866 | }; |
| 5867 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5868 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
| 5869 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5870 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5871 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5872 | }; |
| 5873 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5874 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5875 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5876 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5877 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5878 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5879 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5880 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5881 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5882 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5883 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5884 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5885 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5886 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5887 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5888 | |
| 5889 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5890 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5891 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5892 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5893 | } |
| 5894 | |
Matt Menke | cb2cd098 | 2018-12-19 17:54:04 | [diff] [blame] | 5895 | // Test the case where a proxied H2 session doesn't exist when an auth challenge |
| 5896 | // is observed, but does exist by the time auth credentials are provided. |
| 5897 | // Proxy-Connection: Close is used so that there's a second DNS lookup, which is |
| 5898 | // what causes the existing H2 session to be noticed and reused. |
| 5899 | TEST_F(HttpNetworkTransactionTest, ProxiedH2SessionAppearsDuringAuth) { |
| 5900 | ProxyConfig proxy_config; |
| 5901 | proxy_config.set_auto_detect(true); |
| 5902 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 5903 | |
| 5904 | CapturingProxyResolver capturing_proxy_resolver; |
| 5905 | capturing_proxy_resolver.set_proxy_server( |
| 5906 | ProxyServer(ProxyServer::SCHEME_HTTP, HostPortPair("myproxy", 70))); |
| 5907 | session_deps_.proxy_resolution_service = |
| 5908 | std::make_unique<ProxyResolutionService>( |
| 5909 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 5910 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 5911 | std::make_unique<CapturingProxyResolverFactory>( |
| 5912 | &capturing_proxy_resolver), |
| 5913 | nullptr); |
| 5914 | |
| 5915 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 5916 | |
| 5917 | const char kMyUrl[] = "https://www.example.org/"; |
| 5918 | spdy::SpdySerializedFrame get(spdy_util_.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 5919 | spdy::SpdySerializedFrame get_resp( |
| 5920 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 5921 | spdy::SpdySerializedFrame body(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 5922 | |
| 5923 | spdy_util_.UpdateWithStreamDestruction(1); |
| 5924 | spdy::SpdySerializedFrame get2( |
| 5925 | spdy_util_.ConstructSpdyGet(kMyUrl, 3, LOWEST)); |
| 5926 | spdy::SpdySerializedFrame get_resp2( |
| 5927 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 5928 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
| 5929 | |
| 5930 | MockWrite auth_challenge_writes[] = { |
| 5931 | MockWrite(ASYNC, 0, |
| 5932 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5933 | "Host: www.example.org:443\r\n" |
| 5934 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 5935 | }; |
| 5936 | |
| 5937 | MockRead auth_challenge_reads[] = { |
| 5938 | MockRead(ASYNC, 1, |
| 5939 | "HTTP/1.1 407 Authentication Required\r\n" |
| 5940 | "Content-Length: 0\r\n" |
| 5941 | "Proxy-Connection: close\r\n" |
| 5942 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
| 5943 | }; |
| 5944 | |
| 5945 | MockWrite spdy_writes[] = { |
| 5946 | MockWrite(ASYNC, 0, |
| 5947 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5948 | "Host: www.example.org:443\r\n" |
| 5949 | "Proxy-Connection: keep-alive\r\n" |
| 5950 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 5951 | CreateMockWrite(get, 2), |
| 5952 | CreateMockWrite(get2, 5), |
| 5953 | }; |
| 5954 | |
| 5955 | MockRead spdy_reads[] = { |
| 5956 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\n\r\n"), |
| 5957 | CreateMockRead(get_resp, 3, ASYNC), |
| 5958 | CreateMockRead(body, 4, ASYNC), |
| 5959 | CreateMockRead(get_resp2, 6, ASYNC), |
| 5960 | CreateMockRead(body2, 7, ASYNC), |
| 5961 | |
| 5962 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 8), |
| 5963 | }; |
| 5964 | |
| 5965 | SequencedSocketData auth_challenge1(auth_challenge_reads, |
| 5966 | auth_challenge_writes); |
| 5967 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge1); |
| 5968 | |
| 5969 | SequencedSocketData auth_challenge2(auth_challenge_reads, |
| 5970 | auth_challenge_writes); |
| 5971 | session_deps_.socket_factory->AddSocketDataProvider(&auth_challenge2); |
| 5972 | |
| 5973 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
| 5974 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5975 | |
| 5976 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 5977 | ssl.next_proto = kProtoHTTP2; |
| 5978 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5979 | |
| 5980 | TestCompletionCallback callback; |
| 5981 | std::string response_data; |
| 5982 | |
| 5983 | // Run first request until an auth challenge is observed. |
| 5984 | HttpRequestInfo request1; |
| 5985 | request1.method = "GET"; |
| 5986 | request1.url = GURL(kMyUrl); |
| 5987 | request1.traffic_annotation = |
| 5988 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 5989 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 5990 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 5991 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 5992 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 5993 | ASSERT_TRUE(response); |
| 5994 | ASSERT_TRUE(response->headers); |
| 5995 | EXPECT_EQ(407, response->headers->response_code()); |
| 5996 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5997 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 5998 | |
| 5999 | // Run second request until an auth challenge is observed. |
| 6000 | HttpRequestInfo request2; |
| 6001 | request2.method = "GET"; |
| 6002 | request2.url = GURL(kMyUrl); |
| 6003 | request2.traffic_annotation = |
| 6004 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6005 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6006 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6007 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6008 | response = trans2.GetResponseInfo(); |
| 6009 | ASSERT_TRUE(response); |
| 6010 | ASSERT_TRUE(response->headers); |
| 6011 | EXPECT_EQ(407, response->headers->response_code()); |
| 6012 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6013 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 6014 | |
| 6015 | // Now provide credentials for the first request, and wait for it to complete. |
| 6016 | rv = trans1.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6017 | rv = callback.GetResult(rv); |
| 6018 | EXPECT_THAT(rv, IsOk()); |
| 6019 | response = trans1.GetResponseInfo(); |
| 6020 | ASSERT_TRUE(response); |
| 6021 | ASSERT_TRUE(response->headers); |
| 6022 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6023 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6024 | EXPECT_EQ(kUploadData, response_data); |
| 6025 | |
| 6026 | // Now provide credentials for the second request. It should notice the |
| 6027 | // existing session, and reuse it. |
| 6028 | rv = trans2.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
| 6029 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 6030 | response = trans2.GetResponseInfo(); |
| 6031 | ASSERT_TRUE(response); |
| 6032 | ASSERT_TRUE(response->headers); |
| 6033 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6034 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6035 | EXPECT_EQ(kUploadData, response_data); |
| 6036 | } |
| 6037 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6038 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6039 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6040 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6041 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 6042 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6043 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6044 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6045 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6046 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6047 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6048 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6049 | |
| 6050 | HttpRequestInfo request1; |
| 6051 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6052 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6053 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6054 | request1.traffic_annotation = |
| 6055 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6056 | |
| 6057 | HttpRequestInfo request2; |
| 6058 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6059 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6060 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6061 | request2.traffic_annotation = |
| 6062 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6063 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6064 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6065 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6066 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6067 | spdy::SpdySerializedFrame conn_resp1( |
| 6068 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6069 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6070 | // Fetch https://www.example.org/ via HTTP. |
| 6071 | const char get1[] = |
| 6072 | "GET / HTTP/1.1\r\n" |
| 6073 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6074 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6075 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6076 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6077 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6078 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6079 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6080 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6081 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6082 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6083 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6084 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6085 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6086 | // CONNECT to mail.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6087 | spdy::SpdyHeaderBlock connect2_block; |
| 6088 | connect2_block[spdy::kHttp2MethodHeader] = "CONNECT"; |
| 6089 | connect2_block[spdy::kHttp2AuthorityHeader] = "mail.example.org:443"; |
| 6090 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6091 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 6092 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6093 | spdy::SpdySerializedFrame conn_resp2( |
| 6094 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6095 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6096 | // Fetch https://mail.example.org/ via HTTP. |
| 6097 | const char get2[] = |
| 6098 | "GET / HTTP/1.1\r\n" |
| 6099 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6100 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6101 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6102 | spdy_util_.ConstructSpdyDataFrame(3, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6103 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6104 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6105 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6106 | spdy_util_.ConstructSpdyDataFrame(3, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6107 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6108 | spdy_util_.ConstructSpdyDataFrame(3, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6109 | |
| 6110 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6111 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6112 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6113 | }; |
| 6114 | |
| 6115 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6116 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6117 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 6118 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 6119 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 6120 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 6121 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 6122 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6123 | }; |
| 6124 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6125 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6126 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6127 | |
| 6128 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6129 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6130 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6131 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6132 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6133 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6134 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6135 | |
| 6136 | TestCompletionCallback callback; |
| 6137 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6138 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6139 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6140 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6141 | |
| 6142 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6143 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6144 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6145 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6146 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6147 | ASSERT_TRUE(response); |
| 6148 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6149 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6150 | |
| 6151 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6152 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6153 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6154 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6155 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6156 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6157 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6158 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6159 | |
| 6160 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6161 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6162 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 6163 | // to be created, so the socket's load timing looks like a fresh connection. |
| 6164 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6165 | |
| 6166 | // The requests should have different IDs, since they each are using their own |
| 6167 | // separate stream. |
| 6168 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6169 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6170 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6171 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6172 | } |
| 6173 | |
| 6174 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 6175 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6176 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6177 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 6178 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6179 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6180 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6181 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6182 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6183 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6184 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6185 | |
| 6186 | HttpRequestInfo request1; |
| 6187 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6188 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6189 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6190 | request1.traffic_annotation = |
| 6191 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6192 | |
| 6193 | HttpRequestInfo request2; |
| 6194 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6195 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6196 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6197 | request2.traffic_annotation = |
| 6198 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6199 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6200 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6201 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6202 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6203 | spdy::SpdySerializedFrame conn_resp1( |
| 6204 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6205 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6206 | // Fetch https://www.example.org/ via HTTP. |
| 6207 | const char get1[] = |
| 6208 | "GET / HTTP/1.1\r\n" |
| 6209 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6210 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6211 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6212 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6213 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 6214 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6215 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6216 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6217 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6218 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6219 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6220 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6221 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6222 | // Fetch https://www.example.org/2 via HTTP. |
| 6223 | const char get2[] = |
| 6224 | "GET /2 HTTP/1.1\r\n" |
| 6225 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6226 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6227 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6228 | spdy_util_.ConstructSpdyDataFrame(1, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6229 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 6230 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6231 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6232 | spdy_util_.ConstructSpdyDataFrame(1, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6233 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 6234 | spdy_util_.ConstructSpdyDataFrame(1, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6235 | |
| 6236 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6237 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 6238 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6239 | }; |
| 6240 | |
| 6241 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6242 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 6243 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6244 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6245 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 6246 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6247 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6248 | }; |
| 6249 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6250 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6251 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6252 | |
| 6253 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6254 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6255 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6256 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6257 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6258 | |
| 6259 | TestCompletionCallback callback; |
| 6260 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6261 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6262 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6263 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6264 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6265 | |
| 6266 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6267 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6268 | |
| 6269 | LoadTimingInfo load_timing_info; |
| 6270 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6271 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 6272 | |
| 6273 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6274 | ASSERT_TRUE(response); |
| 6275 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6276 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 6277 | |
| 6278 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6279 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6280 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6281 | trans.reset(); |
| 6282 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6283 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6284 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6285 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6286 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6287 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6288 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6289 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6290 | |
| 6291 | LoadTimingInfo load_timing_info2; |
| 6292 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 6293 | TestLoadTimingReused(load_timing_info2); |
| 6294 | |
| 6295 | // The requests should have the same ID. |
| 6296 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6297 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 6298 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6299 | } |
| 6300 | |
| 6301 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 6302 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6303 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6304 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6305 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6306 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6307 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6308 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6309 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6310 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6311 | |
| 6312 | HttpRequestInfo request1; |
| 6313 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6314 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6315 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6316 | request1.traffic_annotation = |
| 6317 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6318 | |
| 6319 | HttpRequestInfo request2; |
| 6320 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6321 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6322 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6323 | request2.traffic_annotation = |
| 6324 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6325 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6326 | // http://www.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6327 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6328 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6329 | spdy::SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6330 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6331 | spdy::SpdySerializedFrame get_resp1( |
| 6332 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 6333 | spdy::SpdySerializedFrame body1( |
| 6334 | spdy_util_.ConstructSpdyDataFrame(1, "1", true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 6335 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6336 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6337 | // http://mail.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6338 | spdy::SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6339 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6340 | spdy::SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 6341 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6342 | spdy::SpdySerializedFrame get_resp2( |
| 6343 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 6344 | spdy::SpdySerializedFrame body2( |
| 6345 | spdy_util_.ConstructSpdyDataFrame(3, "22", true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6346 | |
| 6347 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6348 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6349 | }; |
| 6350 | |
| 6351 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 6352 | CreateMockRead(get_resp1, 1, ASYNC), |
| 6353 | CreateMockRead(body1, 2, ASYNC), |
| 6354 | CreateMockRead(get_resp2, 4, ASYNC), |
| 6355 | CreateMockRead(body2, 5, ASYNC), |
| 6356 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6357 | }; |
| 6358 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6359 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6360 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6361 | |
| 6362 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 6363 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6364 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6365 | |
| 6366 | TestCompletionCallback callback; |
| 6367 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 6368 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 6369 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6370 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6371 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6372 | |
| 6373 | LoadTimingInfo load_timing_info; |
| 6374 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 6375 | TestLoadTimingNotReused(load_timing_info, |
| 6376 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6377 | |
| 6378 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6379 | ASSERT_TRUE(response); |
| 6380 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 6381 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6382 | |
| 6383 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 6384 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6385 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 6386 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6387 | // Delete the first request, so the second one can reuse the socket. |
| 6388 | trans.reset(); |
| 6389 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6390 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6391 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6392 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6393 | |
| 6394 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6395 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6396 | TestLoadTimingReused(load_timing_info2); |
| 6397 | |
| 6398 | // The requests should have the same ID. |
| 6399 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 6400 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6401 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 6402 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 6403 | } |
| 6404 | |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 6405 | // Test that an HTTP/2 CONNECT through an HTTPS Proxy to a HTTP/2 server and a |
| 6406 | // direct (non-proxied) request to the proxy server are not pooled, as that |
| 6407 | // would break socket pool isolation. |
| 6408 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation1) { |
| 6409 | ProxyConfig proxy_config; |
| 6410 | proxy_config.set_auto_detect(true); |
| 6411 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6412 | |
| 6413 | CapturingProxyResolver capturing_proxy_resolver; |
| 6414 | session_deps_.proxy_resolution_service = |
| 6415 | std::make_unique<ProxyResolutionService>( |
| 6416 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6417 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6418 | std::make_unique<CapturingProxyResolverFactory>( |
| 6419 | &capturing_proxy_resolver), |
| 6420 | nullptr); |
| 6421 | |
| 6422 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6423 | |
| 6424 | SpdyTestUtil spdy_util1; |
| 6425 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6426 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
| 6427 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 6428 | // fetch https://www.example.org/ via HTTP/2. |
| 6429 | const char kMyUrl[] = "https://www.example.org/"; |
| 6430 | spdy::SpdySerializedFrame get(spdy_util1.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6431 | spdy::SpdySerializedFrame wrapped_get( |
| 6432 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6433 | spdy::SpdySerializedFrame conn_resp( |
| 6434 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 6435 | spdy::SpdySerializedFrame get_resp( |
| 6436 | spdy_util1.ConstructSpdyGetReply(NULL, 0, 1)); |
| 6437 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6438 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6439 | spdy::SpdySerializedFrame body(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6440 | spdy::SpdySerializedFrame wrapped_body( |
| 6441 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6442 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6443 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6444 | spdy::SpdySerializedFrame window_update_body( |
| 6445 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6446 | |
| 6447 | MockWrite spdy_writes1[] = { |
| 6448 | CreateMockWrite(connect, 0), |
| 6449 | CreateMockWrite(wrapped_get, 2), |
| 6450 | CreateMockWrite(window_update_get_resp, 6), |
| 6451 | CreateMockWrite(window_update_body, 7), |
| 6452 | }; |
| 6453 | |
| 6454 | MockRead spdy_reads1[] = { |
| 6455 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6456 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6457 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6458 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6459 | MockRead(ASYNC, 0, 8), |
| 6460 | }; |
| 6461 | |
| 6462 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6463 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6464 | |
| 6465 | // Fetch https://proxy:70/ via HTTP/2. Needs a new SpdyTestUtil, since it uses |
| 6466 | // a new pipe. |
| 6467 | SpdyTestUtil spdy_util2; |
| 6468 | spdy::SpdySerializedFrame req( |
| 6469 | spdy_util2.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6470 | MockWrite spdy_writes2[] = {CreateMockWrite(req, 0)}; |
| 6471 | |
| 6472 | spdy::SpdySerializedFrame resp( |
| 6473 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6474 | spdy::SpdySerializedFrame data(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6475 | MockRead spdy_reads2[] = { |
| 6476 | CreateMockRead(resp, 1), |
| 6477 | CreateMockRead(data, 2), |
| 6478 | MockRead(ASYNC, 0, 3), |
| 6479 | }; |
| 6480 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6481 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6482 | |
| 6483 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6484 | ssl.next_proto = kProtoHTTP2; |
| 6485 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6486 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6487 | ssl2.next_proto = kProtoHTTP2; |
| 6488 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6489 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6490 | ssl3.next_proto = kProtoHTTP2; |
| 6491 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6492 | |
| 6493 | TestCompletionCallback callback; |
| 6494 | std::string response_data; |
| 6495 | |
| 6496 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6497 | capturing_proxy_resolver.set_proxy_server( |
| 6498 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6499 | HttpRequestInfo request1; |
| 6500 | request1.method = "GET"; |
| 6501 | request1.url = GURL("https://www.example.org/"); |
| 6502 | request1.traffic_annotation = |
| 6503 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6504 | |
| 6505 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6506 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 6507 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6508 | |
| 6509 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6510 | base::RunLoop().RunUntilIdle(); |
| 6511 | // Now allow the read of the response to complete. |
| 6512 | spdy_data1.Resume(); |
| 6513 | rv = callback.WaitForResult(); |
| 6514 | EXPECT_THAT(rv, IsOk()); |
| 6515 | |
| 6516 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 6517 | ASSERT_TRUE(response); |
| 6518 | ASSERT_TRUE(response->headers); |
| 6519 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 6520 | |
| 6521 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6522 | EXPECT_EQ(kUploadData, response_data); |
| 6523 | RunUntilIdle(); |
| 6524 | |
| 6525 | // Make a direct HTTP/2 request to proxy:70. |
| 6526 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6527 | HttpRequestInfo request2; |
| 6528 | request2.method = "GET"; |
| 6529 | request2.url = GURL("https://proxy:70/"); |
| 6530 | request2.traffic_annotation = |
| 6531 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6532 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6533 | EXPECT_THAT(callback.GetResult(trans2.Start(&request2, callback.callback(), |
| 6534 | NetLogWithSource())), |
| 6535 | IsOk()); |
| 6536 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6537 | } |
| 6538 | |
| 6539 | // Same as above, but reverse request order, since the code to check for an |
| 6540 | // existing session is different for tunnels and direct connections. |
| 6541 | TEST_F(HttpNetworkTransactionTest, SpdyProxyIsolation2) { |
| 6542 | // Configure against https proxy server "myproxy:80". |
| 6543 | ProxyConfig proxy_config; |
| 6544 | proxy_config.set_auto_detect(true); |
| 6545 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 6546 | |
| 6547 | CapturingProxyResolver capturing_proxy_resolver; |
| 6548 | session_deps_.proxy_resolution_service = |
| 6549 | std::make_unique<ProxyResolutionService>( |
| 6550 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 6551 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 6552 | std::make_unique<CapturingProxyResolverFactory>( |
| 6553 | &capturing_proxy_resolver), |
| 6554 | nullptr); |
| 6555 | |
| 6556 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6557 | // Fetch https://proxy:70/ via HTTP/2. |
| 6558 | SpdyTestUtil spdy_util1; |
| 6559 | spdy::SpdySerializedFrame req( |
| 6560 | spdy_util1.ConstructSpdyGet("https://proxy:70/", 1, LOWEST)); |
| 6561 | MockWrite spdy_writes1[] = {CreateMockWrite(req, 0)}; |
| 6562 | |
| 6563 | spdy::SpdySerializedFrame resp( |
| 6564 | spdy_util1.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6565 | spdy::SpdySerializedFrame data(spdy_util1.ConstructSpdyDataFrame(1, true)); |
| 6566 | MockRead spdy_reads1[] = { |
| 6567 | CreateMockRead(resp, 1), |
| 6568 | CreateMockRead(data, 2), |
| 6569 | MockRead(ASYNC, 0, 3), |
| 6570 | }; |
| 6571 | SequencedSocketData spdy_data1(spdy_reads1, spdy_writes1); |
| 6572 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data1); |
| 6573 | |
| 6574 | SpdyTestUtil spdy_util2; |
| 6575 | // CONNECT to www.example.org:443 via HTTP/2. |
| 6576 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
| 6577 | nullptr, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 6578 | // fetch https://www.example.org/ via HTTP/2. |
| 6579 | const char kMyUrl[] = "https://www.example.org/"; |
| 6580 | spdy::SpdySerializedFrame get(spdy_util2.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
| 6581 | spdy::SpdySerializedFrame wrapped_get( |
| 6582 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 6583 | spdy::SpdySerializedFrame conn_resp( |
| 6584 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6585 | spdy::SpdySerializedFrame get_resp( |
| 6586 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 6587 | spdy::SpdySerializedFrame wrapped_get_resp( |
| 6588 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
| 6589 | spdy::SpdySerializedFrame body(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 6590 | spdy::SpdySerializedFrame wrapped_body( |
| 6591 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
| 6592 | spdy::SpdySerializedFrame window_update_get_resp( |
| 6593 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
| 6594 | spdy::SpdySerializedFrame window_update_body( |
| 6595 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
| 6596 | |
| 6597 | MockWrite spdy_writes2[] = { |
| 6598 | CreateMockWrite(connect, 0), |
| 6599 | CreateMockWrite(wrapped_get, 2), |
| 6600 | CreateMockWrite(window_update_get_resp, 6), |
| 6601 | CreateMockWrite(window_update_body, 7), |
| 6602 | }; |
| 6603 | |
| 6604 | MockRead spdy_reads2[] = { |
| 6605 | CreateMockRead(conn_resp, 1, ASYNC), |
| 6606 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 6607 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 6608 | CreateMockRead(wrapped_body, 5, ASYNC), |
| 6609 | MockRead(ASYNC, 0, 8), |
| 6610 | }; |
| 6611 | |
| 6612 | SequencedSocketData spdy_data2(spdy_reads2, spdy_writes2); |
| 6613 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data2); |
| 6614 | |
| 6615 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 6616 | ssl.next_proto = kProtoHTTP2; |
| 6617 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 6618 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6619 | ssl2.next_proto = kProtoHTTP2; |
| 6620 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6621 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6622 | ssl3.next_proto = kProtoHTTP2; |
| 6623 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6624 | |
| 6625 | TestCompletionCallback callback; |
| 6626 | std::string response_data; |
| 6627 | |
| 6628 | // Make a direct HTTP/2 request to proxy:70. |
| 6629 | capturing_proxy_resolver.set_proxy_server(ProxyServer::Direct()); |
| 6630 | HttpRequestInfo request1; |
| 6631 | request1.method = "GET"; |
| 6632 | request1.url = GURL("https://proxy:70/"); |
| 6633 | request1.traffic_annotation = |
| 6634 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6635 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
| 6636 | EXPECT_THAT(callback.GetResult(trans1.Start(&request1, callback.callback(), |
| 6637 | NetLogWithSource())), |
| 6638 | IsOk()); |
| 6639 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 6640 | RunUntilIdle(); |
| 6641 | |
| 6642 | // Make a request using proxy:70 as a HTTP/2 proxy. |
| 6643 | capturing_proxy_resolver.set_proxy_server( |
| 6644 | ProxyServer(ProxyServer::SCHEME_HTTPS, HostPortPair("proxy", 70))); |
| 6645 | HttpRequestInfo request2; |
| 6646 | request2.method = "GET"; |
| 6647 | request2.url = GURL("https://www.example.org/"); |
| 6648 | request2.traffic_annotation = |
| 6649 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6650 | |
| 6651 | HttpNetworkTransaction trans2(LOWEST, session.get()); |
| 6652 | int rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
| 6653 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6654 | |
| 6655 | // Allow the SpdyProxyClientSocket's write callback to complete. |
| 6656 | base::RunLoop().RunUntilIdle(); |
| 6657 | // Now allow the read of the response to complete. |
| 6658 | spdy_data2.Resume(); |
| 6659 | rv = callback.WaitForResult(); |
| 6660 | EXPECT_THAT(rv, IsOk()); |
| 6661 | |
| 6662 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
| 6663 | ASSERT_TRUE(response2); |
| 6664 | ASSERT_TRUE(response2->headers); |
| 6665 | EXPECT_EQ("HTTP/1.1 200", response2->headers->GetStatusLine()); |
| 6666 | |
| 6667 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 6668 | EXPECT_EQ(kUploadData, response_data); |
| 6669 | } |
| 6670 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6671 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6672 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6673 | HttpRequestInfo request; |
| 6674 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6675 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6676 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 6677 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6678 | request.traffic_annotation = |
| 6679 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6680 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6681 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6682 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6683 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 6684 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6685 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6686 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6687 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6688 | // Since we have proxy, should use full url |
| 6689 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6690 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6691 | "Host: www.example.org\r\n" |
| 6692 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6693 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6694 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6695 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6696 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 6697 | "Host: www.example.org\r\n" |
| 6698 | "Proxy-Connection: keep-alive\r\n" |
| 6699 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6700 | }; |
| 6701 | |
| 6702 | // The proxy responds to the GET with a 407, using a persistent |
| 6703 | // connection. |
| 6704 | MockRead data_reads1[] = { |
| 6705 | // No credentials. |
| 6706 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 6707 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6708 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 6709 | MockRead("Content-Length: 0\r\n\r\n"), |
| 6710 | |
| 6711 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6712 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6713 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6714 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6715 | }; |
| 6716 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6717 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6718 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6719 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6720 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6721 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6722 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6723 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6724 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6725 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6726 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6727 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6728 | |
| 6729 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6730 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6731 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6732 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6733 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6734 | TestLoadTimingNotReused(load_timing_info, |
| 6735 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 6736 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6737 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6738 | ASSERT_TRUE(response); |
| 6739 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6740 | EXPECT_EQ(407, response->headers->response_code()); |
| 6741 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 6742 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6743 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6744 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6745 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6746 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6747 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6748 | |
| 6749 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6750 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6751 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6752 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6753 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 6754 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 6755 | TestLoadTimingReused(load_timing_info); |
| 6756 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6757 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6758 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6759 | |
| 6760 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 6761 | EXPECT_EQ(200, response->headers->response_code()); |
| 6762 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 6763 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 6764 | |
| 6765 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6766 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 6767 | } |
| 6768 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6769 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6770 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6771 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6772 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6773 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6774 | request.traffic_annotation = |
| 6775 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6776 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6777 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6778 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6779 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6780 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6781 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6782 | // Since we have proxy, should try to establish tunnel. |
| 6783 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 6784 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 6785 | "Host: www.example.org:443\r\n" |
| 6786 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6787 | }; |
| 6788 | |
| 6789 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 6790 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 6791 | // No response body because the test stops reading here. |
| 6792 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6793 | }; |
| 6794 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6795 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6796 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6797 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6798 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6799 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6800 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6801 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6802 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6803 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6804 | |
| 6805 | rv = callback.WaitForResult(); |
| 6806 | EXPECT_EQ(expected_status, rv); |
| 6807 | } |
| 6808 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 6809 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 6810 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6811 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6812 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6813 | } |
| 6814 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6815 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6816 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 6817 | } |
| 6818 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6819 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6820 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 6821 | } |
| 6822 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6823 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6824 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 6825 | } |
| 6826 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6827 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6828 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 6829 | } |
| 6830 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6831 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6832 | ConnectStatusHelper( |
| 6833 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 6834 | } |
| 6835 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6836 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6837 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 6838 | } |
| 6839 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6840 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6841 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 6842 | } |
| 6843 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6844 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6845 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 6846 | } |
| 6847 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6848 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6849 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 6850 | } |
| 6851 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6852 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6853 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 6854 | } |
| 6855 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6856 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6857 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 6858 | } |
| 6859 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6860 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6861 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 6862 | } |
| 6863 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6864 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6865 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 6866 | } |
| 6867 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6868 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6869 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 6870 | } |
| 6871 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6872 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6873 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 6874 | } |
| 6875 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6876 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6877 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 6878 | } |
| 6879 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6880 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 6881 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 6882 | } |
| 6883 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6884 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6885 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 6886 | } |
| 6887 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6888 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6889 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 6890 | } |
| 6891 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6892 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6893 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 6894 | } |
| 6895 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6896 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6897 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 6898 | } |
| 6899 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6900 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6901 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 6902 | } |
| 6903 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6904 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6905 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 6906 | } |
| 6907 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6908 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6909 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 6910 | } |
| 6911 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6912 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6913 | ConnectStatusHelperWithExpectedStatus( |
| 6914 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 6915 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6916 | } |
| 6917 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6918 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6919 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 6920 | } |
| 6921 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6922 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6923 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 6924 | } |
| 6925 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6926 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6927 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 6928 | } |
| 6929 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6930 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6931 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 6932 | } |
| 6933 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6934 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6935 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 6936 | } |
| 6937 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6938 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6939 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 6940 | } |
| 6941 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6942 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6943 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 6944 | } |
| 6945 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6946 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6947 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 6948 | } |
| 6949 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6950 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6951 | ConnectStatusHelper( |
| 6952 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 6953 | } |
| 6954 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6955 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6956 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 6957 | } |
| 6958 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6959 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6960 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 6961 | } |
| 6962 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6963 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6964 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 6965 | } |
| 6966 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6967 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6968 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 6969 | } |
| 6970 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6971 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6972 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 6973 | } |
| 6974 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6975 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6976 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 6977 | } |
| 6978 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6979 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6980 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 6981 | } |
| 6982 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6983 | // Test the flow when both the proxy server AND origin server require |
| 6984 | // authentication. Again, this uses basic auth for both since that is |
| 6985 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6986 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6987 | HttpRequestInfo request; |
| 6988 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6989 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6990 | request.traffic_annotation = |
| 6991 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6992 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6993 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6994 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6995 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6996 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6997 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6998 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6999 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7000 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7001 | MockWrite( |
| 7002 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7003 | "Host: www.example.org\r\n" |
| 7004 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7005 | }; |
| 7006 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7007 | MockRead data_reads1[] = { |
| 7008 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 7009 | // Give a couple authenticate options (only the middle one is actually |
| 7010 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 7011 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7012 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7013 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 7014 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7015 | // Large content-length -- won't matter, as connection will be reset. |
| 7016 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7017 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7018 | }; |
| 7019 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7020 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7021 | // request we should be issuing -- the final header line contains the |
| 7022 | // proxy's credentials. |
| 7023 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7024 | MockWrite( |
| 7025 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7026 | "Host: www.example.org\r\n" |
| 7027 | "Proxy-Connection: keep-alive\r\n" |
| 7028 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7029 | }; |
| 7030 | |
| 7031 | // Now the proxy server lets the request pass through to origin server. |
| 7032 | // The origin server responds with a 401. |
| 7033 | MockRead data_reads2[] = { |
| 7034 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7035 | // Note: We are using the same realm-name as the proxy server. This is |
| 7036 | // completely valid, as realms are unique across hosts. |
| 7037 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7038 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7039 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7040 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7041 | }; |
| 7042 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7043 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7044 | // the credentials for both the proxy and origin server. |
| 7045 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7046 | MockWrite( |
| 7047 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 7048 | "Host: www.example.org\r\n" |
| 7049 | "Proxy-Connection: keep-alive\r\n" |
| 7050 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 7051 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7052 | }; |
| 7053 | |
| 7054 | // Lastly we get the desired content. |
| 7055 | MockRead data_reads3[] = { |
| 7056 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7057 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 7058 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7059 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7060 | }; |
| 7061 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7062 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7063 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7064 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7065 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7066 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7067 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7068 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7069 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7070 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7071 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7072 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7073 | |
| 7074 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7075 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7076 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7077 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7078 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7079 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7080 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7081 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7082 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7083 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7084 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7085 | |
| 7086 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7087 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7088 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7089 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7090 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7091 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7092 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7093 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7094 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7095 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 7096 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7097 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7098 | |
| 7099 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7100 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7101 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7102 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7103 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7104 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 7105 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7106 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7107 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 7108 | // can't hook into its internals to cause it to generate predictable NTLM |
| 7109 | // authorization headers. |
| 7110 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7111 | // The NTLM authentication unit tests are based on known test data from the |
| 7112 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 7113 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 7114 | // for the implementation and testing of the protocol. |
| 7115 | // |
| 7116 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7117 | |
| 7118 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7119 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7120 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7121 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7122 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7123 | request.traffic_annotation = |
| 7124 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7125 | |
| 7126 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7127 | // to other auth schemes. |
| 7128 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7129 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7130 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7131 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7132 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7133 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7134 | // Generate the NTLM messages based on known test data. |
| 7135 | std::string negotiate_msg; |
| 7136 | std::string challenge_msg; |
| 7137 | std::string authenticate_msg; |
| 7138 | base::Base64Encode( |
| 7139 | base::StringPiece( |
| 7140 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7141 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7142 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7143 | base::Base64Encode( |
| 7144 | base::StringPiece( |
| 7145 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7146 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7147 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7148 | base::Base64Encode( |
| 7149 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7150 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7151 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7152 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7153 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7154 | &authenticate_msg); |
| 7155 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7156 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7157 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7158 | "Host: server\r\n" |
| 7159 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7160 | }; |
| 7161 | |
| 7162 | MockRead data_reads1[] = { |
| 7163 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7164 | // Negotiate and NTLM are often requested together. However, we only want |
| 7165 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7166 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7167 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7168 | MockRead("Connection: close\r\n"), |
| 7169 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7170 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7171 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7172 | }; |
| 7173 | |
| 7174 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7175 | // After restarting with a null identity, this is the |
| 7176 | // request we should be issuing -- the final header line contains a Type |
| 7177 | // 1 message. |
| 7178 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7179 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7180 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7181 | "Authorization: NTLM "), |
| 7182 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7183 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7184 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7185 | // (using correct credentials). The second request continues on the |
| 7186 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7187 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7188 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7189 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7190 | "Authorization: NTLM "), |
| 7191 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7192 | }; |
| 7193 | |
| 7194 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7195 | // The origin server responds with a Type 2 message. |
| 7196 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7197 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7198 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7199 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7200 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7201 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7202 | // Lastly we get the desired content. |
| 7203 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7204 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7205 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7206 | }; |
| 7207 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7208 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7209 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7210 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7211 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7212 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7213 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7214 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7215 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7216 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7217 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7218 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7219 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7220 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7221 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7222 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7223 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7224 | |
| 7225 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7226 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7227 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7228 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7229 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7230 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7231 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7232 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7233 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7234 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7235 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7236 | rv = trans.RestartWithAuth( |
| 7237 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7238 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7239 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7240 | |
| 7241 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7242 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7243 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7244 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7245 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7246 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7247 | ASSERT_TRUE(response); |
| 7248 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7249 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7250 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7251 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7252 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7253 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7254 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7255 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7256 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7257 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7258 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7259 | ASSERT_TRUE(response); |
| 7260 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7261 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7262 | |
| 7263 | std::string response_data; |
| 7264 | rv = ReadTransaction(&trans, &response_data); |
| 7265 | EXPECT_THAT(rv, IsOk()); |
| 7266 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7267 | |
| 7268 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7269 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7270 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7271 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 7272 | } |
| 7273 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7274 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7275 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7276 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7277 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7278 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7279 | request.traffic_annotation = |
| 7280 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7281 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7282 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7283 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7284 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7285 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7286 | // Generate the NTLM messages based on known test data. |
| 7287 | std::string negotiate_msg; |
| 7288 | std::string challenge_msg; |
| 7289 | std::string authenticate_msg; |
| 7290 | base::Base64Encode( |
| 7291 | base::StringPiece( |
| 7292 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7293 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7294 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7295 | base::Base64Encode( |
| 7296 | base::StringPiece( |
| 7297 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7298 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7299 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7300 | base::Base64Encode( |
| 7301 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7302 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7303 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7304 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7305 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7306 | &authenticate_msg); |
| 7307 | |
| 7308 | // The authenticate message when |kWrongPassword| is sent. |
| 7309 | std::string wrong_password_authenticate_msg( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7310 | "TlRMTVNTUAADAAAAGAAYAFgAAACKAIoAcAAAAAwADAD6AAAACAAIAAYBAAAQABAADgEAAAAA" |
| 7311 | "AABYAAAAA4IIAAAAAAAAAAAAAPknEYqtJQtusopDRSfYzAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 7312 | "AAAAAOtVz38osnFdRRggUQHUJ3EBAQAAAAAAAIALyP0A1NIBqqqqqqqqqqoAAAAAAgAMAEQA" |
| 7313 | "bwBtAGEAaQBuAAEADABTAGUAcgB2AGUAcgAGAAQAAgAAAAoAEAAAAAAAAAAAAAAAAAAAAAAA" |
| 7314 | "CQAWAEgAVABUAFAALwBzAGUAcgB2AGUAcgAAAAAAAAAAAEQAbwBtAGEAaQBuAFUAcwBlAHIA" |
| 7315 | "QwBPAE0AUABVAFQARQBSAA=="); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7316 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7317 | // Sanity check that it's the same length as the correct authenticate message |
| 7318 | // and that it's different. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7319 | ASSERT_EQ(authenticate_msg.length(), |
| 7320 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7321 | ASSERT_NE(authenticate_msg, wrong_password_authenticate_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7322 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7323 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7324 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 7325 | "Host: server\r\n" |
| 7326 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7327 | }; |
| 7328 | |
| 7329 | MockRead data_reads1[] = { |
| 7330 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 7331 | // Negotiate and NTLM are often requested together. However, we only want |
| 7332 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 7333 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7334 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 7335 | MockRead("Connection: close\r\n"), |
| 7336 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 7337 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7338 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7339 | }; |
| 7340 | |
| 7341 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7342 | // After restarting with a null identity, this is the |
| 7343 | // request we should be issuing -- the final header line contains a Type |
| 7344 | // 1 message. |
| 7345 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7346 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7347 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7348 | "Authorization: NTLM "), |
| 7349 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7350 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7351 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7352 | // (using incorrect credentials). The second request continues on the |
| 7353 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7354 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7355 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7356 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7357 | "Authorization: NTLM "), |
| 7358 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7359 | }; |
| 7360 | |
| 7361 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7362 | // The origin server responds with a Type 2 message. |
| 7363 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7364 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7365 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 7366 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7367 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7368 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7369 | // Wrong password. |
| 7370 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 7371 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 7372 | MockRead("Content-Length: 42\r\n"), |
| 7373 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7374 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7375 | }; |
| 7376 | |
| 7377 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7378 | // After restarting with a null identity, this is the |
| 7379 | // request we should be issuing -- the final header line contains a Type |
| 7380 | // 1 message. |
| 7381 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7382 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7383 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7384 | "Authorization: NTLM "), |
| 7385 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7386 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7387 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7388 | // (the credentials for the origin server). The second request continues |
| 7389 | // on the same connection. |
| 7390 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7391 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7392 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7393 | "Authorization: NTLM "), |
| 7394 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7395 | }; |
| 7396 | |
| 7397 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7398 | // The origin server responds with a Type 2 message. |
| 7399 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7400 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7401 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7402 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7403 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7404 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7405 | // Lastly we get the desired content. |
| 7406 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7407 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 7408 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7409 | }; |
| 7410 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7411 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7412 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7413 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7414 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7415 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7416 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7417 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7418 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7419 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7420 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 7421 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 7422 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 7423 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 7424 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7425 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7426 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7427 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 7428 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7429 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7430 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7431 | |
| 7432 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7433 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7434 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7435 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7436 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7437 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7438 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7439 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7440 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7441 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7442 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7443 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7444 | rv = trans.RestartWithAuth( |
| 7445 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 7446 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7447 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7448 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7449 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7450 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7451 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7452 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7453 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7454 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7455 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7456 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7457 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7458 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7459 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7460 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7461 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7462 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7463 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7464 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7465 | |
| 7466 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7467 | rv = trans.RestartWithAuth( |
| 7468 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7469 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7470 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7471 | |
| 7472 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7473 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7474 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7475 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7476 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7477 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 7478 | |
| 7479 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7480 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7481 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7482 | |
| 7483 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7484 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7485 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7486 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7487 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7488 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7489 | |
| 7490 | std::string response_data; |
| 7491 | rv = ReadTransaction(&trans, &response_data); |
| 7492 | EXPECT_THAT(rv, IsOk()); |
| 7493 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7494 | |
| 7495 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7496 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 7497 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 7498 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 7499 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 7500 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7501 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7502 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7503 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 7504 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7505 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7506 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7507 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7508 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7509 | const char* kUrl = "https://server/kids/login.aspx"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7510 | |
| 7511 | HttpRequestInfo request; |
| 7512 | request.method = "GET"; |
| 7513 | request.url = GURL(kUrl); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7514 | request.traffic_annotation = |
| 7515 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7516 | |
| 7517 | // First request without credentials. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7518 | spdy::SpdyHeaderBlock request_headers0( |
| 7519 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 7520 | spdy::SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7521 | 1, std::move(request_headers0), LOWEST, true)); |
| 7522 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7523 | spdy::SpdyHeaderBlock response_headers0; |
| 7524 | response_headers0[spdy::kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7525 | response_headers0["www-authenticate"] = "NTLM"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7526 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7527 | 1, std::move(response_headers0), true)); |
| 7528 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7529 | // Stream 1 is closed. |
| 7530 | spdy_util_.UpdateWithStreamDestruction(1); |
| 7531 | |
| 7532 | // Generate the NTLM messages based on known test data. |
| 7533 | std::string negotiate_msg; |
| 7534 | std::string challenge_msg; |
| 7535 | std::string authenticate_msg; |
| 7536 | base::Base64Encode( |
| 7537 | base::StringPiece( |
| 7538 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7539 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7540 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7541 | base::Base64Encode( |
| 7542 | base::StringPiece( |
| 7543 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7544 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7545 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7546 | base::Base64Encode( |
| 7547 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 7548 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7549 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7550 | base::size( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7551 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7552 | &authenticate_msg); |
| 7553 | |
| 7554 | // Retry with authorization header. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7555 | spdy::SpdyHeaderBlock request_headers1( |
| 7556 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7557 | request_headers1["authorization"] = std::string("NTLM ") + negotiate_msg; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7558 | spdy::SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7559 | 3, std::move(request_headers1), LOWEST, true)); |
| 7560 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 7561 | spdy::SpdySerializedFrame rst( |
| 7562 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_HTTP_1_1_REQUIRED)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7563 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 7564 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
| 7565 | MockRead reads0[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7566 | |
| 7567 | // Retry yet again using HTTP/1.1. |
| 7568 | MockWrite writes1[] = { |
| 7569 | // After restarting with a null identity, this is the |
| 7570 | // request we should be issuing -- the final header line contains a Type |
| 7571 | // 1 message. |
| 7572 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7573 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7574 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7575 | "Authorization: NTLM "), |
| 7576 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7577 | |
| 7578 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 7579 | // (the credentials for the origin server). The second request continues |
| 7580 | // on the same connection. |
| 7581 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 7582 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7583 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7584 | "Authorization: NTLM "), |
| 7585 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7586 | }; |
| 7587 | |
| 7588 | MockRead reads1[] = { |
| 7589 | // The origin server responds with a Type 2 message. |
| 7590 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7591 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 7592 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7593 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 7594 | MockRead("You are not authorized to view this page\r\n"), |
| 7595 | |
| 7596 | // Lastly we get the desired content. |
| 7597 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7598 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7599 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7600 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7601 | SequencedSocketData data0(reads0, writes0); |
| 7602 | StaticSocketDataProvider data1(reads1, writes1); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7603 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 7604 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7605 | |
| 7606 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 7607 | ssl0.next_proto = kProtoHTTP2; |
| 7608 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 7609 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 7610 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 7611 | |
| 7612 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7613 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7614 | |
| 7615 | TestCompletionCallback callback1; |
| 7616 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 7617 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7618 | |
| 7619 | rv = callback1.WaitForResult(); |
| 7620 | EXPECT_THAT(rv, IsOk()); |
| 7621 | |
| 7622 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7623 | |
| 7624 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7625 | ASSERT_TRUE(response); |
| 7626 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
| 7627 | |
| 7628 | TestCompletionCallback callback2; |
| 7629 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 7630 | rv = trans.RestartWithAuth( |
| 7631 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7632 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7633 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7634 | |
| 7635 | rv = callback2.WaitForResult(); |
| 7636 | EXPECT_THAT(rv, IsOk()); |
| 7637 | |
| 7638 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7639 | |
| 7640 | response = trans.GetResponseInfo(); |
| 7641 | ASSERT_TRUE(response); |
| 7642 | EXPECT_FALSE(response->auth_challenge); |
| 7643 | |
| 7644 | TestCompletionCallback callback3; |
| 7645 | |
| 7646 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 7647 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7648 | |
| 7649 | rv = callback3.WaitForResult(); |
| 7650 | EXPECT_THAT(rv, IsOk()); |
| 7651 | |
| 7652 | response = trans.GetResponseInfo(); |
| 7653 | ASSERT_TRUE(response); |
| 7654 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 7655 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 7656 | |
| 7657 | std::string response_data; |
| 7658 | rv = ReadTransaction(&trans, &response_data); |
| 7659 | EXPECT_THAT(rv, IsOk()); |
| 7660 | EXPECT_EQ("Please Login\r\n", response_data); |
| 7661 | |
| 7662 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 7663 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 7664 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 7665 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 7666 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7667 | |
| 7668 | // Test that, if we have an NTLM proxy and the origin resets the connection, we |
| 7669 | // do no retry forever checking for TLS version interference. This is a |
| 7670 | // regression test for https://crbug.com/823387. |
| 7671 | TEST_F(HttpNetworkTransactionTest, NTLMProxyTLSHandshakeReset) { |
| 7672 | // The NTLM test data expects the proxy to be named 'server'. The origin is |
| 7673 | // https://origin/. |
| 7674 | session_deps_.proxy_resolution_service = |
| 7675 | ProxyResolutionService::CreateFixedFromPacResult( |
| 7676 | "PROXY server", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7677 | |
| 7678 | SSLConfig config; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7679 | session_deps_.ssl_config_service = |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 7680 | std::make_unique<TestSSLConfigService>(config); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7681 | |
| 7682 | HttpRequestInfo request; |
| 7683 | request.method = "GET"; |
| 7684 | request.url = GURL("https://origin/"); |
| 7685 | request.traffic_annotation = |
| 7686 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7687 | |
| 7688 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 7689 | // to other auth schemes. |
| 7690 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 7691 | |
| 7692 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 7693 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
| 7694 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7695 | |
| 7696 | // Generate the NTLM messages based on known test data. |
| 7697 | std::string negotiate_msg; |
| 7698 | std::string challenge_msg; |
| 7699 | std::string authenticate_msg; |
| 7700 | base::Base64Encode( |
| 7701 | base::StringPiece( |
| 7702 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7703 | base::size(ntlm::test::kExpectedNegotiateMsg)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7704 | &negotiate_msg); |
| 7705 | base::Base64Encode( |
| 7706 | base::StringPiece( |
| 7707 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7708 | base::size(ntlm::test::kChallengeMsgFromSpecV2)), |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7709 | &challenge_msg); |
| 7710 | base::Base64Encode( |
| 7711 | base::StringPiece( |
| 7712 | reinterpret_cast<const char*>( |
| 7713 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 7714 | base::size( |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7715 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
| 7716 | &authenticate_msg); |
| 7717 | |
| 7718 | MockWrite data_writes[] = { |
| 7719 | // The initial CONNECT request. |
| 7720 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7721 | "Host: origin:443\r\n" |
| 7722 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 7723 | |
| 7724 | // After restarting with an identity. |
| 7725 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7726 | "Host: origin:443\r\n" |
| 7727 | "Proxy-Connection: keep-alive\r\n" |
| 7728 | "Proxy-Authorization: NTLM "), |
| 7729 | MockWrite(negotiate_msg.c_str()), |
| 7730 | // End headers. |
| 7731 | MockWrite("\r\n\r\n"), |
| 7732 | |
| 7733 | // The second restart. |
| 7734 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 7735 | "Host: origin:443\r\n" |
| 7736 | "Proxy-Connection: keep-alive\r\n" |
| 7737 | "Proxy-Authorization: NTLM "), |
| 7738 | MockWrite(authenticate_msg.c_str()), |
| 7739 | // End headers. |
| 7740 | MockWrite("\r\n\r\n"), |
| 7741 | }; |
| 7742 | |
| 7743 | MockRead data_reads[] = { |
| 7744 | // The initial NTLM response. |
| 7745 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7746 | "Content-Length: 0\r\n" |
| 7747 | "Proxy-Authenticate: NTLM\r\n\r\n"), |
| 7748 | |
| 7749 | // The NTLM challenge message. |
| 7750 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 7751 | "Content-Length: 0\r\n" |
| 7752 | "Proxy-Authenticate: NTLM "), |
| 7753 | MockRead(challenge_msg.c_str()), |
| 7754 | // End headers. |
| 7755 | MockRead("\r\n\r\n"), |
| 7756 | |
| 7757 | // Finally the tunnel is established. |
| 7758 | MockRead("HTTP/1.1 200 Connected\r\n\r\n"), |
| 7759 | }; |
| 7760 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7761 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7762 | SSLSocketDataProvider data_ssl(ASYNC, ERR_CONNECTION_RESET); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7763 | StaticSocketDataProvider data2(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7764 | SSLSocketDataProvider data_ssl2(ASYNC, ERR_CONNECTION_RESET); |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 7765 | data_ssl2.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 7766 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7767 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl); |
| 7768 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7769 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl2); |
| 7770 | |
| 7771 | // Start the transaction. The proxy responds with an NTLM authentication |
| 7772 | // request. |
| 7773 | TestCompletionCallback callback; |
| 7774 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7775 | int rv = callback.GetResult( |
| 7776 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 7777 | |
| 7778 | EXPECT_THAT(rv, IsOk()); |
| 7779 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 7780 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7781 | ASSERT_TRUE(response); |
| 7782 | EXPECT_TRUE(CheckNTLMProxyAuth(response->auth_challenge.get())); |
| 7783 | |
| 7784 | // Configure credentials. The proxy responds with the challenge message. |
| 7785 | rv = callback.GetResult(trans.RestartWithAuth( |
| 7786 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 7787 | callback.callback())); |
| 7788 | EXPECT_THAT(rv, IsOk()); |
| 7789 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7790 | response = trans.GetResponseInfo(); |
| 7791 | ASSERT_TRUE(response); |
| 7792 | EXPECT_FALSE(response->auth_challenge); |
| 7793 | |
| 7794 | // Restart once more. The tunnel will be established and the the SSL handshake |
| 7795 | // will reset. The TLS 1.3 version interference probe will then kick in and |
| 7796 | // restart the process. The proxy responds with another NTLM authentiation |
| 7797 | // request, but we don't need to provide credentials as the cached ones work/ |
| 7798 | rv = callback.GetResult( |
| 7799 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7800 | EXPECT_THAT(rv, IsOk()); |
| 7801 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7802 | response = trans.GetResponseInfo(); |
| 7803 | ASSERT_TRUE(response); |
| 7804 | EXPECT_FALSE(response->auth_challenge); |
| 7805 | |
| 7806 | // The proxy responds with the NTLM challenge message. |
| 7807 | rv = callback.GetResult( |
| 7808 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7809 | EXPECT_THAT(rv, IsOk()); |
| 7810 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 7811 | response = trans.GetResponseInfo(); |
| 7812 | ASSERT_TRUE(response); |
| 7813 | EXPECT_FALSE(response->auth_challenge); |
| 7814 | |
| 7815 | // Send the NTLM authenticate message. The tunnel is established and the |
| 7816 | // handshake resets again. We should not retry again. |
| 7817 | rv = callback.GetResult( |
| 7818 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 7819 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
| 7820 | } |
| 7821 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7822 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 7823 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7824 | // Test reading a server response which has only headers, and no body. |
| 7825 | // After some maximum number of bytes is consumed, the transaction should |
| 7826 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7827 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7828 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7829 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7830 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7831 | request.traffic_annotation = |
| 7832 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7833 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7834 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7835 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7836 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7837 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 7838 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7839 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7840 | |
| 7841 | MockRead data_reads[] = { |
| 7842 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7843 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7844 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7845 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7846 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7847 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7848 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7849 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7850 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7851 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7852 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7853 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7854 | |
| 7855 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7856 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7857 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7858 | |
| 7859 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 7860 | // establish tunnel. |
| 7861 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7862 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7863 | HttpRequestInfo request; |
| 7864 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7865 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7866 | request.traffic_annotation = |
| 7867 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7868 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7869 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 7870 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 7871 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 7872 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7873 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7874 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7875 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7876 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7877 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7878 | // Since we have proxy, should try to establish tunnel. |
| 7879 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7880 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7881 | "Host: www.example.org:443\r\n" |
| 7882 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7883 | }; |
| 7884 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7885 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7886 | // connection. Usually a proxy would return 501 (not implemented), |
| 7887 | // or 200 (tunnel established). |
| 7888 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 7889 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7890 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7891 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7892 | }; |
| 7893 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7894 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7895 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7896 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7897 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7898 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7899 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7900 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7901 | |
| 7902 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7903 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7904 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7905 | // Empty the current queue. This is necessary because idle sockets are |
| 7906 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7907 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7908 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7909 | // We now check to make sure the TCPClientSocket was not added back to |
| 7910 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7911 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7912 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7913 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7914 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7915 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7916 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7917 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7918 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7919 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7920 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7921 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7922 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7923 | request.traffic_annotation = |
| 7924 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7925 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7926 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7927 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7928 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7929 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7930 | MockRead data_reads[] = { |
| 7931 | // A part of the response body is received with the response headers. |
| 7932 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7933 | // The rest of the response body is received in two parts. |
| 7934 | MockRead("lo"), |
| 7935 | MockRead(" world"), |
| 7936 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7937 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7938 | }; |
| 7939 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7940 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7941 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7942 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7943 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7944 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7945 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7946 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7947 | |
| 7948 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7949 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7950 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7951 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7952 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7953 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7954 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7955 | std::string status_line = response->headers->GetStatusLine(); |
| 7956 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7957 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7958 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7959 | |
| 7960 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7961 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7962 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7963 | EXPECT_EQ("hello world", response_data); |
| 7964 | |
| 7965 | // Empty the current queue. This is necessary because idle sockets are |
| 7966 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7967 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7968 | |
| 7969 | // We now check to make sure the socket was added back to the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7970 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7971 | } |
| 7972 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7973 | // Make sure that we recycle a SSL socket after reading all of the response |
| 7974 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7975 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7976 | HttpRequestInfo request; |
| 7977 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7978 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7979 | request.traffic_annotation = |
| 7980 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7981 | |
| 7982 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7983 | MockWrite( |
| 7984 | "GET / HTTP/1.1\r\n" |
| 7985 | "Host: www.example.org\r\n" |
| 7986 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7987 | }; |
| 7988 | |
| 7989 | MockRead data_reads[] = { |
| 7990 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7991 | MockRead("Content-Length: 11\r\n\r\n"), |
| 7992 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7993 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7994 | }; |
| 7995 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7996 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7997 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7998 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7999 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8000 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8001 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8002 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8003 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8004 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8005 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8006 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8007 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8008 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8009 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8010 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8011 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8012 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8013 | ASSERT_TRUE(response); |
| 8014 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8015 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8016 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8017 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8018 | |
| 8019 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8020 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8021 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8022 | EXPECT_EQ("hello world", response_data); |
| 8023 | |
| 8024 | // Empty the current queue. This is necessary because idle sockets are |
| 8025 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8026 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8027 | |
| 8028 | // We now check to make sure the socket was added back to the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8029 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8030 | } |
| 8031 | |
| 8032 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 8033 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8034 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8035 | HttpRequestInfo request; |
| 8036 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8037 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8038 | request.traffic_annotation = |
| 8039 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8040 | |
| 8041 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8042 | MockWrite( |
| 8043 | "GET / HTTP/1.1\r\n" |
| 8044 | "Host: www.example.org\r\n" |
| 8045 | "Connection: keep-alive\r\n\r\n"), |
| 8046 | MockWrite( |
| 8047 | "GET / HTTP/1.1\r\n" |
| 8048 | "Host: www.example.org\r\n" |
| 8049 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8050 | }; |
| 8051 | |
| 8052 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 8053 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8054 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8055 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8056 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8057 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8058 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8059 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8060 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8061 | StaticSocketDataProvider data(data_reads, data_writes); |
| 8062 | StaticSocketDataProvider data2(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8063 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8064 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8065 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8066 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8067 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8068 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8069 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8070 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8071 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8072 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8073 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8074 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8075 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8076 | |
| 8077 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8078 | ASSERT_TRUE(response); |
| 8079 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8080 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8081 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8082 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8083 | |
| 8084 | std::string response_data; |
| 8085 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8086 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8087 | EXPECT_EQ("hello world", response_data); |
| 8088 | |
| 8089 | // Empty the current queue. This is necessary because idle sockets are |
| 8090 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8091 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8092 | |
| 8093 | // We now check to make sure the socket was added back to the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8094 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8095 | |
| 8096 | // Now start the second transaction, which should reuse the previous socket. |
| 8097 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 8098 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8099 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8100 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8101 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8102 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8103 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8104 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8105 | |
| 8106 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8107 | ASSERT_TRUE(response); |
| 8108 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8109 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8110 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8111 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8112 | |
| 8113 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8114 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8115 | EXPECT_EQ("hello world", response_data); |
| 8116 | |
| 8117 | // Empty the current queue. This is necessary because idle sockets are |
| 8118 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8119 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8120 | |
| 8121 | // We now check to make sure the socket was added back to the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8122 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 8123 | } |
| 8124 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8125 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8126 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8127 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8128 | HttpRequestInfo request; |
| 8129 | request.method = "GET"; |
| 8130 | request.url = GURL("http://www.example.org/"); |
| 8131 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8132 | request.traffic_annotation = |
| 8133 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8134 | |
| 8135 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8136 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8137 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8138 | |
| 8139 | MockRead data_reads[] = { |
| 8140 | // A part of the response body is received with the response headers. |
| 8141 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8142 | // The rest of the response body is received in two parts. |
| 8143 | MockRead("lo"), MockRead(" world"), |
| 8144 | MockRead("junk"), // Should not be read!! |
| 8145 | MockRead(SYNCHRONOUS, OK), |
| 8146 | }; |
| 8147 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8148 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8149 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8150 | |
| 8151 | TestCompletionCallback callback; |
| 8152 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8153 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8154 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8155 | |
| 8156 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8157 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8158 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8159 | ASSERT_TRUE(response); |
| 8160 | EXPECT_TRUE(response->headers); |
| 8161 | std::string status_line = response->headers->GetStatusLine(); |
| 8162 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8163 | |
| 8164 | // Make memory critical notification and ensure the transaction still has been |
| 8165 | // operating right. |
| 8166 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8167 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8168 | base::RunLoop().RunUntilIdle(); |
| 8169 | |
| 8170 | // Socket should not be flushed as long as it is not idle. |
| 8171 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8172 | |
| 8173 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8174 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8175 | EXPECT_THAT(rv, IsOk()); |
| 8176 | EXPECT_EQ("hello world", response_data); |
| 8177 | |
| 8178 | // Empty the current queue. This is necessary because idle sockets are |
| 8179 | // added to the connection pool asynchronously with a PostTask. |
| 8180 | base::RunLoop().RunUntilIdle(); |
| 8181 | |
| 8182 | // We now check to make sure the socket was added back to the pool. |
| 8183 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8184 | |
| 8185 | // Idle sockets should be flushed now. |
| 8186 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8187 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8188 | base::RunLoop().RunUntilIdle(); |
| 8189 | |
| 8190 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8191 | } |
| 8192 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8193 | // Disable idle socket closing on memory pressure. |
| 8194 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 8195 | // low memory notification and ensure the socket pool is NOT flushed. |
| 8196 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 8197 | HttpRequestInfo request; |
| 8198 | request.method = "GET"; |
| 8199 | request.url = GURL("http://www.example.org/"); |
| 8200 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8201 | request.traffic_annotation = |
| 8202 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8203 | |
| 8204 | // Disable idle socket closing on memory pressure. |
| 8205 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 8206 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 8207 | |
| 8208 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 8209 | |
| 8210 | MockRead data_reads[] = { |
| 8211 | // A part of the response body is received with the response headers. |
| 8212 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 8213 | // The rest of the response body is received in two parts. |
| 8214 | MockRead("lo"), MockRead(" world"), |
| 8215 | MockRead("junk"), // Should not be read!! |
| 8216 | MockRead(SYNCHRONOUS, OK), |
| 8217 | }; |
| 8218 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8219 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 8220 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8221 | |
| 8222 | TestCompletionCallback callback; |
| 8223 | |
| 8224 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 8225 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 8226 | |
| 8227 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8228 | |
| 8229 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 8230 | ASSERT_TRUE(response); |
| 8231 | EXPECT_TRUE(response->headers); |
| 8232 | std::string status_line = response->headers->GetStatusLine(); |
| 8233 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 8234 | |
| 8235 | // Make memory critical notification and ensure the transaction still has been |
| 8236 | // operating right. |
| 8237 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8238 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8239 | base::RunLoop().RunUntilIdle(); |
| 8240 | |
| 8241 | // Socket should not be flushed as long as it is not idle. |
| 8242 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8243 | |
| 8244 | std::string response_data; |
| 8245 | rv = ReadTransaction(&trans, &response_data); |
| 8246 | EXPECT_THAT(rv, IsOk()); |
| 8247 | EXPECT_EQ("hello world", response_data); |
| 8248 | |
| 8249 | // Empty the current queue. This is necessary because idle sockets are |
| 8250 | // added to the connection pool asynchronously with a PostTask. |
| 8251 | base::RunLoop().RunUntilIdle(); |
| 8252 | |
| 8253 | // We now check to make sure the socket was added back to the pool. |
| 8254 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8255 | |
| 8256 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 8257 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8258 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 8259 | base::RunLoop().RunUntilIdle(); |
| 8260 | |
| 8261 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8262 | |
| 8263 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 8264 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8265 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8266 | base::RunLoop().RunUntilIdle(); |
| 8267 | |
| 8268 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 8269 | } |
| 8270 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8271 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 8272 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8273 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8274 | HttpRequestInfo request; |
| 8275 | request.method = "GET"; |
| 8276 | request.url = GURL("https://www.example.org/"); |
| 8277 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8278 | request.traffic_annotation = |
| 8279 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8280 | |
| 8281 | MockWrite data_writes[] = { |
| 8282 | MockWrite("GET / HTTP/1.1\r\n" |
| 8283 | "Host: www.example.org\r\n" |
| 8284 | "Connection: keep-alive\r\n\r\n"), |
| 8285 | }; |
| 8286 | |
| 8287 | MockRead data_reads[] = { |
| 8288 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 8289 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 8290 | |
| 8291 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 8292 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 8293 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8294 | StaticSocketDataProvider data(data_reads, data_writes); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8295 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8296 | |
| 8297 | TestCompletionCallback callback; |
| 8298 | |
| 8299 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8300 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8301 | |
| 8302 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8303 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8304 | |
| 8305 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 8306 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8307 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8308 | ASSERT_TRUE(response); |
| 8309 | ASSERT_TRUE(response->headers); |
| 8310 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8311 | |
| 8312 | // Make memory critical notification and ensure the transaction still has been |
| 8313 | // operating right. |
| 8314 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8315 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8316 | base::RunLoop().RunUntilIdle(); |
| 8317 | |
| 8318 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 8319 | |
| 8320 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8321 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 8322 | EXPECT_THAT(rv, IsOk()); |
| 8323 | EXPECT_EQ("hello world", response_data); |
| 8324 | |
| 8325 | // Empty the current queue. This is necessary because idle sockets are |
| 8326 | // added to the connection pool asynchronously with a PostTask. |
| 8327 | base::RunLoop().RunUntilIdle(); |
| 8328 | |
| 8329 | // We now check to make sure the socket was added back to the pool. |
| 8330 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 8331 | |
| 8332 | // Make memory notification once again and ensure idle socket is closed. |
| 8333 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 8334 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 8335 | base::RunLoop().RunUntilIdle(); |
| 8336 | |
| 8337 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 8338 | } |
| 8339 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8340 | // Make sure that we recycle a socket after a zero-length response. |
| 8341 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8342 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8343 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8344 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8345 | request.url = GURL( |
| 8346 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 8347 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 8348 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 8349 | "rt=prt.2642,ol.2649,xjs.2951"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8350 | request.traffic_annotation = |
| 8351 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8352 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8353 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8354 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8355 | MockRead data_reads[] = { |
| 8356 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 8357 | "Content-Length: 0\r\n" |
| 8358 | "Content-Type: text/html\r\n\r\n"), |
| 8359 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8360 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8361 | }; |
| 8362 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8363 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8364 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8365 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8366 | // Transaction must be created after the MockReads, so it's destroyed before |
| 8367 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8368 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 8369 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8370 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8371 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8372 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8373 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8374 | |
| 8375 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8376 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8377 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8378 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8379 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8380 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8381 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8382 | std::string status_line = response->headers->GetStatusLine(); |
| 8383 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 8384 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8385 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8386 | |
| 8387 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8388 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8389 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8390 | EXPECT_EQ("", response_data); |
| 8391 | |
| 8392 | // Empty the current queue. This is necessary because idle sockets are |
| 8393 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8394 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8395 | |
| 8396 | // We now check to make sure the socket was added back to the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8397 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 8398 | } |
| 8399 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8400 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8401 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8402 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 8403 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 8404 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8405 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8406 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8407 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 8408 | // after use. |
| 8409 | request[0].method = "GET"; |
| 8410 | request[0].url = GURL("http://www.google.com/"); |
| 8411 | request[0].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8412 | request[0].traffic_annotation = |
| 8413 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8414 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 8415 | // transaction 1. The first attempts fails when writing the POST data. |
| 8416 | // This causes the transaction to retry with a new socket. The second |
| 8417 | // attempt succeeds. |
| 8418 | request[1].method = "POST"; |
| 8419 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 8420 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8421 | request[1].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8422 | request[1].traffic_annotation = |
| 8423 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8424 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8425 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8426 | |
| 8427 | // The first socket is used for transaction 1 and the first attempt of |
| 8428 | // transaction 2. |
| 8429 | |
| 8430 | // The response of transaction 1. |
| 8431 | MockRead data_reads1[] = { |
| 8432 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 8433 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8434 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8435 | }; |
| 8436 | // The mock write results of transaction 1 and the first attempt of |
| 8437 | // transaction 2. |
| 8438 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8439 | MockWrite(SYNCHRONOUS, 64), // GET |
| 8440 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8441 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8442 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8443 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8444 | |
| 8445 | // The second socket is used for the second attempt of transaction 2. |
| 8446 | |
| 8447 | // The response of transaction 2. |
| 8448 | MockRead data_reads2[] = { |
| 8449 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 8450 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8451 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8452 | }; |
| 8453 | // The mock write results of the second attempt of transaction 2. |
| 8454 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8455 | MockWrite(SYNCHRONOUS, 93), // POST |
| 8456 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8457 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8458 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8459 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8460 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8461 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8462 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8463 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8464 | "hello world", "welcome" |
| 8465 | }; |
| 8466 | |
| 8467 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8468 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8469 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8470 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8471 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8472 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8473 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8474 | |
| 8475 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8476 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8477 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8478 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8479 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8480 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8481 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8482 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 8483 | |
| 8484 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8485 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8486 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 8487 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 8488 | } |
| 8489 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8490 | |
| 8491 | // Test the request-challenge-retry sequence for basic auth when there is |
| 8492 | // an identity in the URL. The request should be sent as normal, but when |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8493 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8494 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8495 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8496 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8497 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 8498 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8499 | request.traffic_annotation = |
| 8500 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8501 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8502 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8503 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8504 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 8505 | // The password contains an escaped character -- for this test to pass it |
| 8506 | // will need to be unescaped by HttpNetworkTransaction. |
| 8507 | EXPECT_EQ("b%40r", request.url.password()); |
| 8508 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8509 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8510 | MockWrite( |
| 8511 | "GET / HTTP/1.1\r\n" |
| 8512 | "Host: www.example.org\r\n" |
| 8513 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8514 | }; |
| 8515 | |
| 8516 | MockRead data_reads1[] = { |
| 8517 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8518 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8519 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8520 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8521 | }; |
| 8522 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8523 | // After the challenge above, the transaction will be restarted using the |
| 8524 | // identity from the url (foo, b@r) to answer the challenge. |
| 8525 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8526 | MockWrite( |
| 8527 | "GET / HTTP/1.1\r\n" |
| 8528 | "Host: www.example.org\r\n" |
| 8529 | "Connection: keep-alive\r\n" |
| 8530 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8531 | }; |
| 8532 | |
| 8533 | MockRead data_reads2[] = { |
| 8534 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8535 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8536 | MockRead(SYNCHRONOUS, OK), |
| 8537 | }; |
| 8538 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8539 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8540 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8541 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8542 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8543 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8544 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8545 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8546 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8547 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8548 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8549 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8550 | |
| 8551 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8552 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8553 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8554 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8555 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8556 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8557 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8558 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8559 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8560 | |
| 8561 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8562 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8563 | |
| 8564 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8565 | |
| 8566 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8567 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8568 | } |
| 8569 | |
| 8570 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 8571 | // incorrect identity in the URL. The identity from the URL should be used only |
| 8572 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8573 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8574 | HttpRequestInfo request; |
| 8575 | request.method = "GET"; |
| 8576 | // Note: the URL has a username:password in it. The password "baz" is |
| 8577 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8578 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8579 | |
| 8580 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8581 | request.traffic_annotation = |
| 8582 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8583 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8584 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8585 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8586 | |
| 8587 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8588 | MockWrite( |
| 8589 | "GET / HTTP/1.1\r\n" |
| 8590 | "Host: www.example.org\r\n" |
| 8591 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8592 | }; |
| 8593 | |
| 8594 | MockRead data_reads1[] = { |
| 8595 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8596 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8597 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8598 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8599 | }; |
| 8600 | |
| 8601 | // After the challenge above, the transaction will be restarted using the |
| 8602 | // identity from the url (foo, baz) to answer the challenge. |
| 8603 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8604 | MockWrite( |
| 8605 | "GET / HTTP/1.1\r\n" |
| 8606 | "Host: www.example.org\r\n" |
| 8607 | "Connection: keep-alive\r\n" |
| 8608 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8609 | }; |
| 8610 | |
| 8611 | MockRead data_reads2[] = { |
| 8612 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8613 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8614 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8615 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8616 | }; |
| 8617 | |
| 8618 | // After the challenge above, the transaction will be restarted using the |
| 8619 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 8620 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8621 | MockWrite( |
| 8622 | "GET / HTTP/1.1\r\n" |
| 8623 | "Host: www.example.org\r\n" |
| 8624 | "Connection: keep-alive\r\n" |
| 8625 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8626 | }; |
| 8627 | |
| 8628 | MockRead data_reads3[] = { |
| 8629 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8630 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8631 | MockRead(SYNCHRONOUS, OK), |
| 8632 | }; |
| 8633 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8634 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8635 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 8636 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8637 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8638 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8639 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8640 | |
| 8641 | TestCompletionCallback callback1; |
| 8642 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8643 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8644 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8645 | |
| 8646 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8647 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8648 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8649 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8650 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8651 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8652 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8653 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8654 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8655 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8656 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8657 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8658 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8659 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 8660 | |
| 8661 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8662 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8663 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8664 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8665 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8666 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8667 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8668 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8669 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8670 | |
| 8671 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8672 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 8673 | |
| 8674 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8675 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8676 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8677 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 8678 | } |
| 8679 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8680 | |
| 8681 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 8682 | // correct identity in the URL, but its use is being suppressed. The identity |
| 8683 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8684 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8685 | HttpRequestInfo request; |
| 8686 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8687 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8688 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8689 | request.traffic_annotation = |
| 8690 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8691 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8692 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8693 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8694 | |
| 8695 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8696 | MockWrite( |
| 8697 | "GET / HTTP/1.1\r\n" |
| 8698 | "Host: www.example.org\r\n" |
| 8699 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8700 | }; |
| 8701 | |
| 8702 | MockRead data_reads1[] = { |
| 8703 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8704 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8705 | MockRead("Content-Length: 10\r\n\r\n"), |
| 8706 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 8707 | }; |
| 8708 | |
| 8709 | // After the challenge above, the transaction will be restarted using the |
| 8710 | // identity supplied by the user, not the one in the URL, to answer the |
| 8711 | // challenge. |
| 8712 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8713 | MockWrite( |
| 8714 | "GET / HTTP/1.1\r\n" |
| 8715 | "Host: www.example.org\r\n" |
| 8716 | "Connection: keep-alive\r\n" |
| 8717 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8718 | }; |
| 8719 | |
| 8720 | MockRead data_reads3[] = { |
| 8721 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8722 | MockRead("Content-Length: 100\r\n\r\n"), |
| 8723 | MockRead(SYNCHRONOUS, OK), |
| 8724 | }; |
| 8725 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8726 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8727 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8728 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8729 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 8730 | |
| 8731 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8732 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8733 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8734 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8735 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8736 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8737 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8738 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8739 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8740 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 8741 | |
| 8742 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8743 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8744 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8745 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8746 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8747 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8748 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8749 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8750 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8751 | |
| 8752 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8753 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8754 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8755 | |
| 8756 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 8757 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 8758 | } |
| 8759 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8760 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8761 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8762 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8763 | |
| 8764 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8765 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8766 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8767 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8768 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8769 | request.traffic_annotation = |
| 8770 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8771 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8772 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8773 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8774 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8775 | MockWrite( |
| 8776 | "GET /x/y/z HTTP/1.1\r\n" |
| 8777 | "Host: www.example.org\r\n" |
| 8778 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8779 | }; |
| 8780 | |
| 8781 | MockRead data_reads1[] = { |
| 8782 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8783 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8784 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8785 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8786 | }; |
| 8787 | |
| 8788 | // Resend with authorization (username=foo, password=bar) |
| 8789 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8790 | MockWrite( |
| 8791 | "GET /x/y/z HTTP/1.1\r\n" |
| 8792 | "Host: www.example.org\r\n" |
| 8793 | "Connection: keep-alive\r\n" |
| 8794 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8795 | }; |
| 8796 | |
| 8797 | // Sever accepts the authorization. |
| 8798 | MockRead data_reads2[] = { |
| 8799 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8800 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8801 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8802 | }; |
| 8803 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8804 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8805 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8806 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8807 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8808 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8809 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8810 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8811 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8812 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8813 | |
| 8814 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8815 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8816 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8817 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8818 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8819 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8820 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8821 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8822 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8823 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8824 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8825 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8826 | |
| 8827 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8828 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8829 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8830 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8831 | ASSERT_TRUE(response); |
| 8832 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8833 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8834 | } |
| 8835 | |
| 8836 | // ------------------------------------------------------------------------ |
| 8837 | |
| 8838 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 8839 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8840 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8841 | request.method = "GET"; |
| 8842 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8843 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8844 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8845 | request.traffic_annotation = |
| 8846 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8847 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8848 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8849 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8850 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8851 | MockWrite( |
| 8852 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8853 | "Host: www.example.org\r\n" |
| 8854 | "Connection: keep-alive\r\n" |
| 8855 | // Send preemptive authorization for MyRealm1 |
| 8856 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8857 | }; |
| 8858 | |
| 8859 | // The server didn't like the preemptive authorization, and |
| 8860 | // challenges us for a different realm (MyRealm2). |
| 8861 | MockRead data_reads1[] = { |
| 8862 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8863 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 8864 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8865 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8866 | }; |
| 8867 | |
| 8868 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 8869 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8870 | MockWrite( |
| 8871 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8872 | "Host: www.example.org\r\n" |
| 8873 | "Connection: keep-alive\r\n" |
| 8874 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8875 | }; |
| 8876 | |
| 8877 | // Sever accepts the authorization. |
| 8878 | MockRead data_reads2[] = { |
| 8879 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8880 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8881 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8882 | }; |
| 8883 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8884 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8885 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8886 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8887 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8888 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8889 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8890 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8891 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8892 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8893 | |
| 8894 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8895 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8896 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8897 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8898 | ASSERT_TRUE(response); |
| 8899 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8900 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8901 | EXPECT_EQ("http://www.example.org", |
| 8902 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8903 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 8904 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8905 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8906 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8907 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8908 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 8909 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8910 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8911 | |
| 8912 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8913 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8914 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8915 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8916 | ASSERT_TRUE(response); |
| 8917 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8918 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8919 | } |
| 8920 | |
| 8921 | // ------------------------------------------------------------------------ |
| 8922 | |
| 8923 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 8924 | // succeed with preemptive authorization. |
| 8925 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8926 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8927 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8928 | request.url = GURL("http://www.example.org/x/y/z2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8929 | request.traffic_annotation = |
| 8930 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8931 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8932 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8933 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8934 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8935 | MockWrite( |
| 8936 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 8937 | "Host: www.example.org\r\n" |
| 8938 | "Connection: keep-alive\r\n" |
| 8939 | // The authorization for MyRealm1 gets sent preemptively |
| 8940 | // (since the url is in the same protection space) |
| 8941 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8942 | }; |
| 8943 | |
| 8944 | // Sever accepts the preemptive authorization |
| 8945 | MockRead data_reads1[] = { |
| 8946 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8947 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8948 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8949 | }; |
| 8950 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8951 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8952 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8953 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8954 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8955 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8956 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8957 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8958 | |
| 8959 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8960 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8961 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8962 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8963 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8964 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8965 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8966 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8967 | } |
| 8968 | |
| 8969 | // ------------------------------------------------------------------------ |
| 8970 | |
| 8971 | // Transaction 4: request another URL in MyRealm (however the |
| 8972 | // url is not known to belong to the protection space, so no pre-auth). |
| 8973 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8974 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8975 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8976 | request.url = GURL("http://www.example.org/x/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8977 | request.traffic_annotation = |
| 8978 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8979 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8980 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8981 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8982 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8983 | MockWrite( |
| 8984 | "GET /x/1 HTTP/1.1\r\n" |
| 8985 | "Host: www.example.org\r\n" |
| 8986 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8987 | }; |
| 8988 | |
| 8989 | MockRead data_reads1[] = { |
| 8990 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8991 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8992 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8993 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8994 | }; |
| 8995 | |
| 8996 | // Resend with authorization from MyRealm's cache. |
| 8997 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8998 | MockWrite( |
| 8999 | "GET /x/1 HTTP/1.1\r\n" |
| 9000 | "Host: www.example.org\r\n" |
| 9001 | "Connection: keep-alive\r\n" |
| 9002 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9003 | }; |
| 9004 | |
| 9005 | // Sever accepts the authorization. |
| 9006 | MockRead data_reads2[] = { |
| 9007 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9008 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9009 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9010 | }; |
| 9011 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9012 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9013 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9014 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9015 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9016 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9017 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9018 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9019 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9020 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9021 | |
| 9022 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9023 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9024 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9025 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9026 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9027 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9028 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9029 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9030 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9031 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9032 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9033 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9034 | ASSERT_TRUE(response); |
| 9035 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9036 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9037 | } |
| 9038 | |
| 9039 | // ------------------------------------------------------------------------ |
| 9040 | |
| 9041 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 9042 | // cached identity. Should invalidate and re-prompt. |
| 9043 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9044 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9045 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9046 | request.url = GURL("http://www.example.org/p/q/t"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9047 | request.traffic_annotation = |
| 9048 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9049 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9050 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9051 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9052 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9053 | MockWrite( |
| 9054 | "GET /p/q/t HTTP/1.1\r\n" |
| 9055 | "Host: www.example.org\r\n" |
| 9056 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9057 | }; |
| 9058 | |
| 9059 | MockRead data_reads1[] = { |
| 9060 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9061 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9062 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9063 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9064 | }; |
| 9065 | |
| 9066 | // Resend with authorization from cache for MyRealm. |
| 9067 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9068 | MockWrite( |
| 9069 | "GET /p/q/t HTTP/1.1\r\n" |
| 9070 | "Host: www.example.org\r\n" |
| 9071 | "Connection: keep-alive\r\n" |
| 9072 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9073 | }; |
| 9074 | |
| 9075 | // Sever rejects the authorization. |
| 9076 | MockRead data_reads2[] = { |
| 9077 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9078 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9079 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9080 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9081 | }; |
| 9082 | |
| 9083 | // At this point we should prompt for new credentials for MyRealm. |
| 9084 | // Restart with username=foo3, password=foo4. |
| 9085 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9086 | MockWrite( |
| 9087 | "GET /p/q/t HTTP/1.1\r\n" |
| 9088 | "Host: www.example.org\r\n" |
| 9089 | "Connection: keep-alive\r\n" |
| 9090 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9091 | }; |
| 9092 | |
| 9093 | // Sever accepts the authorization. |
| 9094 | MockRead data_reads3[] = { |
| 9095 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9096 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9097 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9098 | }; |
| 9099 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9100 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9101 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 9102 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9103 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9104 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 9105 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9106 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9107 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9108 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9109 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9110 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9111 | |
| 9112 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9113 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9114 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9115 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9116 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9117 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9118 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9119 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9120 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9121 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9122 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9123 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9124 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9125 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9126 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9127 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9128 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9129 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 9130 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9131 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9132 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 9133 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9134 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9135 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9136 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9137 | ASSERT_TRUE(response); |
| 9138 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 9139 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9140 | } |
| 9141 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9142 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9143 | // Tests that nonce count increments when multiple auth attempts |
| 9144 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9145 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 9146 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 9147 | new HttpAuthHandlerDigest::Factory(); |
| 9148 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 9149 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 9150 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9151 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9152 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9153 | |
| 9154 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 9155 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9156 | HttpRequestInfo request; |
| 9157 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9158 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9159 | request.traffic_annotation = |
| 9160 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9161 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9162 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9163 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9164 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9165 | MockWrite( |
| 9166 | "GET /x/y/z HTTP/1.1\r\n" |
| 9167 | "Host: www.example.org\r\n" |
| 9168 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9169 | }; |
| 9170 | |
| 9171 | MockRead data_reads1[] = { |
| 9172 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 9173 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 9174 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9175 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9176 | }; |
| 9177 | |
| 9178 | // Resend with authorization (username=foo, password=bar) |
| 9179 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9180 | MockWrite( |
| 9181 | "GET /x/y/z HTTP/1.1\r\n" |
| 9182 | "Host: www.example.org\r\n" |
| 9183 | "Connection: keep-alive\r\n" |
| 9184 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9185 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 9186 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 9187 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9188 | }; |
| 9189 | |
| 9190 | // Sever accepts the authorization. |
| 9191 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 9192 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9193 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9194 | }; |
| 9195 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9196 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 9197 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9198 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 9199 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9200 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9201 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9202 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9203 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9204 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9205 | |
| 9206 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9207 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9208 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9209 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9210 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 9211 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9212 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9213 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9214 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9215 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9216 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9217 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9218 | |
| 9219 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9220 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9221 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9222 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9223 | ASSERT_TRUE(response); |
| 9224 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9225 | } |
| 9226 | |
| 9227 | // ------------------------------------------------------------------------ |
| 9228 | |
| 9229 | // Transaction 2: Request another resource in digestive's protection space. |
| 9230 | // This will preemptively add an Authorization header which should have an |
| 9231 | // "nc" value of 2 (as compared to 1 in the first use. |
| 9232 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9233 | HttpRequestInfo request; |
| 9234 | request.method = "GET"; |
| 9235 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 9236 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9237 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9238 | request.traffic_annotation = |
| 9239 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9240 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9241 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9242 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9243 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9244 | MockWrite( |
| 9245 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 9246 | "Host: www.example.org\r\n" |
| 9247 | "Connection: keep-alive\r\n" |
| 9248 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 9249 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 9250 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 9251 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9252 | }; |
| 9253 | |
| 9254 | // Sever accepts the authorization. |
| 9255 | MockRead data_reads1[] = { |
| 9256 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9257 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9258 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9259 | }; |
| 9260 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9261 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9262 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9263 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9264 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9265 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9266 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9267 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9268 | |
| 9269 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9270 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9271 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9272 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9273 | ASSERT_TRUE(response); |
| 9274 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 9275 | } |
| 9276 | } |
| 9277 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9278 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9279 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9280 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9281 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9282 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9283 | |
| 9284 | // Setup some state (which we expect ResetStateForRestart() will clear). |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 9285 | trans.read_buf_ = base::MakeRefCounted<IOBuffer>(15); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9286 | trans.read_buf_len_ = 15; |
| 9287 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9288 | |
| 9289 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9290 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9291 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9292 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9293 | response->response_time = base::Time::Now(); |
| 9294 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9295 | |
| 9296 | { // Setup state for response_.vary_data |
| 9297 | HttpRequestInfo request; |
| 9298 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 9299 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 9300 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9301 | request.extra_headers.SetHeader("Foo", "1"); |
| 9302 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9303 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9304 | } |
| 9305 | |
| 9306 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9307 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9308 | |
| 9309 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9310 | EXPECT_FALSE(trans.read_buf_); |
| 9311 | EXPECT_EQ(0, trans.read_buf_len_); |
| 9312 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9313 | EXPECT_FALSE(response->auth_challenge); |
| 9314 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 9315 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 9316 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 9317 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 9318 | } |
| 9319 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9320 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9321 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9322 | HttpRequestInfo request; |
| 9323 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9324 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9325 | request.traffic_annotation = |
| 9326 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9327 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9328 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9329 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9330 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9331 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9332 | MockWrite( |
| 9333 | "GET / HTTP/1.1\r\n" |
| 9334 | "Host: www.example.org\r\n" |
| 9335 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9336 | }; |
| 9337 | |
| 9338 | MockRead data_reads[] = { |
| 9339 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9340 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9341 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9342 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9343 | }; |
| 9344 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 9345 | StaticSocketDataProvider ssl_bad_certificate; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9346 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9347 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9348 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9349 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9350 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9351 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9352 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9353 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9354 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9355 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9356 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9357 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9358 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9359 | |
| 9360 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9361 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9362 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9363 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9364 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9365 | |
| 9366 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9367 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9368 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9369 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9370 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9371 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9372 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9373 | } |
| 9374 | |
| 9375 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 9376 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9377 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9378 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9379 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9380 | |
| 9381 | HttpRequestInfo request; |
| 9382 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9383 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9384 | request.traffic_annotation = |
| 9385 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9386 | |
| 9387 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9388 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9389 | "Host: www.example.org:443\r\n" |
| 9390 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9391 | }; |
| 9392 | |
| 9393 | MockRead proxy_reads[] = { |
| 9394 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9395 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9396 | }; |
| 9397 | |
| 9398 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9399 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9400 | "Host: www.example.org:443\r\n" |
| 9401 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9402 | MockWrite("GET / HTTP/1.1\r\n" |
| 9403 | "Host: www.example.org\r\n" |
| 9404 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9405 | }; |
| 9406 | |
| 9407 | MockRead data_reads[] = { |
| 9408 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9409 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9410 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9411 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9412 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9413 | }; |
| 9414 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9415 | StaticSocketDataProvider ssl_bad_certificate(proxy_reads, proxy_writes); |
| 9416 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9417 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9418 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9419 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9420 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9421 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9422 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 9423 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9424 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9425 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9426 | |
| 9427 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9428 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9429 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9430 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9431 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9432 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9433 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9434 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9435 | |
| 9436 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9437 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9438 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9439 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9440 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9441 | |
| 9442 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9443 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9444 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9445 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9446 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9447 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 9448 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9449 | } |
| 9450 | } |
| 9451 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9452 | |
| 9453 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9454 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9455 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9456 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9457 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9458 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9459 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9460 | |
| 9461 | HttpRequestInfo request; |
| 9462 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9463 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9464 | request.traffic_annotation = |
| 9465 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9466 | |
| 9467 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9468 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9469 | "Host: www.example.org:443\r\n" |
| 9470 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9471 | MockWrite("GET / HTTP/1.1\r\n" |
| 9472 | "Host: www.example.org\r\n" |
| 9473 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9474 | }; |
| 9475 | |
| 9476 | MockRead data_reads[] = { |
| 9477 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9478 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 9479 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9480 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9481 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9482 | }; |
| 9483 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9484 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9485 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 9486 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9487 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9488 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9489 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 9490 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9491 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9492 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9493 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9494 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9495 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9496 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9497 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9498 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9499 | |
| 9500 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9501 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9502 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9503 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9504 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9505 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9506 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9507 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9508 | EXPECT_EQ(200, response->headers->response_code()); |
| 9509 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9510 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9511 | |
| 9512 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9513 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9514 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9515 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9516 | } |
| 9517 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9518 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9519 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9520 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9521 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9522 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9523 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9524 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9525 | |
| 9526 | HttpRequestInfo request; |
| 9527 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9528 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9529 | request.traffic_annotation = |
| 9530 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9531 | |
| 9532 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9533 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9534 | "Host: www.example.org:443\r\n" |
| 9535 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9536 | }; |
| 9537 | |
| 9538 | MockRead data_reads[] = { |
| 9539 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 9540 | MockRead("Location: http://login.example.com/\r\n"), |
| 9541 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9542 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9543 | }; |
| 9544 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9545 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9546 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9547 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9548 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9549 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9550 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9551 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9552 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9553 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9554 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9555 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9556 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9557 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9558 | |
| 9559 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9560 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9561 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9562 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9563 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9564 | |
| 9565 | EXPECT_EQ(302, response->headers->response_code()); |
| 9566 | std::string url; |
| 9567 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 9568 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9569 | |
| 9570 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 9571 | // timing for the proxy connection instead of the connection to the host, |
| 9572 | // and no send / receive times. |
| 9573 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 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 | |
| 9580 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 9581 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 9582 | load_timing_info.proxy_resolve_end); |
| 9583 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 9584 | load_timing_info.connect_timing.connect_start); |
| 9585 | ExpectConnectTimingHasTimes( |
| 9586 | load_timing_info.connect_timing, |
| 9587 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9588 | |
| 9589 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 9590 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 9591 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9592 | } |
| 9593 | |
| 9594 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9595 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9596 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9597 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9598 | |
| 9599 | HttpRequestInfo request; |
| 9600 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9601 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9602 | request.traffic_annotation = |
| 9603 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9604 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9605 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9606 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9607 | spdy::SpdySerializedFrame goaway( |
| 9608 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9609 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9610 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 9611 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9612 | }; |
| 9613 | |
| 9614 | static const char* const kExtraHeaders[] = { |
| 9615 | "location", |
| 9616 | "http://login.example.com/", |
| 9617 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9618 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9619 | "302", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9620 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9621 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9622 | }; |
| 9623 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9624 | SequencedSocketData data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9625 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9626 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9627 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9628 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9629 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9630 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9631 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9632 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9633 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9634 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9635 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9636 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9637 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9638 | |
| 9639 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9640 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9641 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9642 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9643 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9644 | |
| 9645 | EXPECT_EQ(302, response->headers->response_code()); |
| 9646 | std::string url; |
| 9647 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 9648 | EXPECT_EQ("http://login.example.com/", url); |
| 9649 | } |
| 9650 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9651 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9652 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9653 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9654 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9655 | |
| 9656 | HttpRequestInfo request; |
| 9657 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9658 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9659 | request.traffic_annotation = |
| 9660 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9661 | |
| 9662 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9663 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9664 | "Host: www.example.org:443\r\n" |
| 9665 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9666 | }; |
| 9667 | |
| 9668 | MockRead data_reads[] = { |
| 9669 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 9670 | MockRead("Content-Length: 23\r\n\r\n"), |
| 9671 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9672 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9673 | }; |
| 9674 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9675 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9676 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9677 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9678 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9679 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9680 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9681 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9682 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9683 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9684 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9685 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9686 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9687 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9688 | |
| 9689 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9690 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9691 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9692 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9693 | } |
| 9694 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 9695 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9696 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9697 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9698 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9699 | |
| 9700 | HttpRequestInfo request; |
| 9701 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9702 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9703 | request.traffic_annotation = |
| 9704 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9705 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9706 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9707 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9708 | spdy::SpdySerializedFrame rst( |
| 9709 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9710 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9711 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9712 | }; |
| 9713 | |
| 9714 | static const char* const kExtraHeaders[] = { |
| 9715 | "location", |
| 9716 | "http://login.example.com/", |
| 9717 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9718 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9719 | "404", kExtraHeaders, base::size(kExtraHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9720 | spdy::SpdySerializedFrame body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9721 | spdy_util_.ConstructSpdyDataFrame(1, "The host does not exist", true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9722 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9723 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9724 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9725 | }; |
| 9726 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9727 | SequencedSocketData data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9728 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9729 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9730 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9731 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9732 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9733 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9734 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9735 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9736 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9737 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9738 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9739 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9740 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9741 | |
| 9742 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9743 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9744 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 9745 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 9746 | } |
| 9747 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9748 | // Test the request-challenge-retry sequence for basic auth, through |
| 9749 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9750 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9751 | HttpRequestInfo request; |
| 9752 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9753 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9754 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 9755 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9756 | request.traffic_annotation = |
| 9757 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9758 | |
| 9759 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9760 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9761 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9762 | "HTTPS myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9763 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9764 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9765 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9766 | |
| 9767 | // Since we have proxy, should try to establish tunnel. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9768 | spdy::SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9769 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9770 | spdy::SpdySerializedFrame rst( |
| 9771 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 9772 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9773 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9774 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9775 | // be issuing -- the final header line contains the credentials. |
| 9776 | const char* const kAuthCredentials[] = { |
| 9777 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 9778 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9779 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9780 | kAuthCredentials, base::size(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9781 | HostPortPair("www.example.org", 443))); |
| 9782 | // fetch https://www.example.org/ via HTTP |
| 9783 | const char get[] = |
| 9784 | "GET / HTTP/1.1\r\n" |
| 9785 | "Host: www.example.org\r\n" |
| 9786 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9787 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9788 | spdy_util_.ConstructSpdyDataFrame(3, get, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9789 | |
| 9790 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9791 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 9792 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9793 | }; |
| 9794 | |
| 9795 | // The proxy responds to the connect with a 407, using a persistent |
| 9796 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 9797 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9798 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9799 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 9800 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9801 | spdy::SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 9802 | kAuthStatus, kAuthChallenge, base::size(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9803 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9804 | spdy::SpdySerializedFrame conn_resp( |
| 9805 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9806 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 9807 | "Content-Length: 5\r\n\r\n"; |
| 9808 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9809 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9810 | spdy_util_.ConstructSpdyDataFrame(3, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9811 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9812 | spdy_util_.ConstructSpdyDataFrame(3, "hello", false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9813 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9814 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 9815 | CreateMockRead(conn_resp, 4, ASYNC), |
| 9816 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 9817 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 9818 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9819 | }; |
| 9820 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9821 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9822 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9823 | // Negotiate SPDY to the proxy |
| 9824 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9825 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9826 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9827 | // Vanilla SSL to the server |
| 9828 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9829 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9830 | |
| 9831 | TestCompletionCallback callback1; |
| 9832 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9833 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9834 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9835 | |
| 9836 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9837 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9838 | |
| 9839 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9840 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 9841 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9842 | log.GetEntries(&entries); |
| 9843 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 9844 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 9845 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9846 | ExpectLogContainsSomewhere( |
| 9847 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 9848 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 9849 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9850 | |
| 9851 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9852 | ASSERT_TRUE(response); |
| 9853 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9854 | EXPECT_EQ(407, response->headers->response_code()); |
| 9855 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9856 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 9857 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9858 | |
| 9859 | TestCompletionCallback callback2; |
| 9860 | |
| 9861 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9862 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9863 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9864 | |
| 9865 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9866 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9867 | |
| 9868 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9869 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9870 | |
| 9871 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9872 | EXPECT_EQ(200, response->headers->response_code()); |
| 9873 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 9874 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9875 | |
| 9876 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9877 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9878 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9879 | LoadTimingInfo load_timing_info; |
| 9880 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9881 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9882 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9883 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9884 | trans.reset(); |
| 9885 | session->CloseAllConnections(); |
| 9886 | } |
| 9887 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9888 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 9889 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9890 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9891 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9892 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9893 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 9894 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9895 | HttpRequestInfo request; |
| 9896 | HttpRequestInfo push_request; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9897 | request.traffic_annotation = |
| 9898 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9899 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9900 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9901 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9902 | push_request.method = "GET"; |
| 9903 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9904 | push_request.traffic_annotation = |
| 9905 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9906 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9907 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9908 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9909 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9910 | "HTTPS myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9911 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9912 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9913 | |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 9914 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 9915 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9916 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9917 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9918 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9919 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9920 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9921 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9922 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9923 | |
| 9924 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9925 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9926 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9927 | }; |
| 9928 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9929 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 9930 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
| 9931 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9932 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9933 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9934 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9935 | spdy::SpdySerializedFrame stream1_body( |
| 9936 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9937 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9938 | spdy::SpdySerializedFrame stream2_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9939 | spdy_util_.ConstructSpdyDataFrame(2, "pushed", true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9940 | |
| 9941 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 9942 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 9943 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9944 | CreateMockRead(stream1_body, 4, ASYNC), |
| 9945 | CreateMockRead(stream2_body, 5, ASYNC), |
| 9946 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9947 | }; |
| 9948 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9949 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9950 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9951 | // Negotiate SPDY to the proxy |
| 9952 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9953 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9954 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9955 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9956 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9957 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9958 | TestCompletionCallback callback; |
| 9959 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9960 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9961 | |
| 9962 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9963 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9964 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9965 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9966 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9967 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9968 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9969 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9970 | |
| 9971 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9972 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9973 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 9974 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9975 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9976 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9977 | |
| 9978 | EXPECT_EQ(200, response->headers->response_code()); |
| 9979 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9980 | |
| 9981 | std::string response_data; |
| 9982 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9983 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9984 | EXPECT_EQ("hello!", response_data); |
| 9985 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9986 | LoadTimingInfo load_timing_info; |
| 9987 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9988 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9989 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9990 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9991 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9992 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9993 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 9994 | |
| 9995 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9996 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9997 | EXPECT_EQ("pushed", response_data); |
| 9998 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9999 | LoadTimingInfo push_load_timing_info; |
| 10000 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 10001 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 10002 | // The transactions should share a socket ID, despite being for different |
| 10003 | // origins. |
| 10004 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 10005 | push_load_timing_info.socket_log_id); |
| 10006 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 10007 | trans.reset(); |
| 10008 | push_trans.reset(); |
| 10009 | session->CloseAllConnections(); |
| 10010 | } |
| 10011 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10012 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10013 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10014 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10015 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10016 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 10017 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10018 | HttpRequestInfo request; |
| 10019 | |
| 10020 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10021 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10022 | request.traffic_annotation = |
| 10023 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10024 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10025 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10026 | "https://myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10027 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10028 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10029 | |
| 10030 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10031 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10032 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 10033 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10034 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10035 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10036 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10037 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10038 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10039 | spdy::SpdySerializedFrame push_rst( |
| 10040 | spdy_util_.ConstructSpdyRstStream(2, spdy::ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10041 | |
| 10042 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10043 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10044 | }; |
| 10045 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10046 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10047 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10048 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10049 | spdy::SpdySerializedFrame stream1_body( |
| 10050 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10051 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10052 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 10053 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10054 | |
| 10055 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10056 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10057 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 10058 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 10059 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10060 | }; |
| 10061 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10062 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10063 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10064 | // Negotiate SPDY to the proxy |
| 10065 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10066 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10067 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10068 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10069 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10070 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10071 | TestCompletionCallback callback; |
| 10072 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10073 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10074 | |
| 10075 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10076 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10077 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10078 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10079 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10080 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10081 | |
| 10082 | EXPECT_EQ(200, response->headers->response_code()); |
| 10083 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10084 | |
| 10085 | std::string response_data; |
| 10086 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10087 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 10088 | EXPECT_EQ("hello!", response_data); |
| 10089 | |
| 10090 | trans.reset(); |
| 10091 | session->CloseAllConnections(); |
| 10092 | } |
| 10093 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10094 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 10095 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10096 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10097 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10098 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 10099 | proxy_delegate->set_trusted_spdy_proxy( |
| 10100 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 10101 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10102 | HttpRequestInfo request; |
| 10103 | |
| 10104 | request.method = "GET"; |
| 10105 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10106 | request.traffic_annotation = |
| 10107 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10108 | |
| 10109 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10110 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10111 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10112 | BoundTestNetLog log; |
| 10113 | session_deps_.net_log = log.bound().net_log(); |
| 10114 | |
| 10115 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 10116 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 10117 | proxy_delegate.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10118 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10119 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10120 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10121 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 10122 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10123 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10124 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10125 | |
| 10126 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10127 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10128 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10129 | }; |
| 10130 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10131 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10132 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10133 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10134 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 10135 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 10136 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10137 | spdy::SpdySerializedFrame stream1_body( |
| 10138 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10139 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10140 | spdy::SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 10141 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10142 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 10143 | spdy::SpdySerializedFrame stream2_body( |
| 10144 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10145 | |
| 10146 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 10147 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 10148 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 10149 | CreateMockRead(stream1_body, 4, ASYNC), |
| 10150 | CreateMockRead(stream2_body, 5, ASYNC), |
| 10151 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10152 | }; |
| 10153 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10154 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10155 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 10156 | // Negotiate SPDY to the proxy |
| 10157 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 10158 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10159 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 10160 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10161 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10162 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10163 | TestCompletionCallback callback; |
| 10164 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10165 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10166 | |
| 10167 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10168 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10169 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 10170 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10171 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10172 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 10173 | |
| 10174 | EXPECT_EQ(200, response->headers->response_code()); |
| 10175 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 10176 | |
| 10177 | std::string response_data; |
| 10178 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10179 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 10180 | EXPECT_EQ("hello!", response_data); |
| 10181 | |
| 10182 | trans.reset(); |
| 10183 | session->CloseAllConnections(); |
| 10184 | } |
| 10185 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10186 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 10187 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10188 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10189 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10190 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10191 | |
| 10192 | HttpRequestInfo request; |
| 10193 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10194 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10195 | request.traffic_annotation = |
| 10196 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10197 | |
| 10198 | // Attempt to fetch the URL from a server with a bad cert |
| 10199 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10200 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10201 | "Host: www.example.org:443\r\n" |
| 10202 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10203 | }; |
| 10204 | |
| 10205 | MockRead bad_cert_reads[] = { |
| 10206 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10207 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10208 | }; |
| 10209 | |
| 10210 | // Attempt to fetch the URL with a good cert |
| 10211 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10212 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10213 | "Host: www.example.org:443\r\n" |
| 10214 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 10215 | MockWrite("GET / HTTP/1.1\r\n" |
| 10216 | "Host: www.example.org\r\n" |
| 10217 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10218 | }; |
| 10219 | |
| 10220 | MockRead good_cert_reads[] = { |
| 10221 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 10222 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10223 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10224 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10225 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10226 | }; |
| 10227 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10228 | StaticSocketDataProvider ssl_bad_certificate(bad_cert_reads, bad_cert_writes); |
| 10229 | StaticSocketDataProvider data(good_cert_reads, good_data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10230 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 10231 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10232 | |
| 10233 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10234 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10235 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 10236 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10237 | |
| 10238 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10239 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 10240 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10241 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10242 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10243 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10244 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10245 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10246 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10247 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10248 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10249 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10250 | |
| 10251 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10252 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10253 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10254 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10255 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10256 | |
| 10257 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10258 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10259 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10260 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10261 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10262 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 10263 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10264 | } |
| 10265 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10266 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10267 | HttpRequestInfo request; |
| 10268 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10269 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10270 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10271 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10272 | request.traffic_annotation = |
| 10273 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10274 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10275 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10276 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10277 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10278 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10279 | MockWrite( |
| 10280 | "GET / HTTP/1.1\r\n" |
| 10281 | "Host: www.example.org\r\n" |
| 10282 | "Connection: keep-alive\r\n" |
| 10283 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10284 | }; |
| 10285 | |
| 10286 | // Lastly, the server responds with the actual content. |
| 10287 | MockRead data_reads[] = { |
| 10288 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10289 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10290 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10291 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10292 | }; |
| 10293 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10294 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10295 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10296 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10297 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10298 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10299 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10300 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10301 | |
| 10302 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10303 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10304 | } |
| 10305 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10306 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10307 | HttpRequestInfo request; |
| 10308 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10309 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10310 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 10311 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10312 | request.traffic_annotation = |
| 10313 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10314 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10315 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10316 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10317 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10318 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10319 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10320 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 10321 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 10322 | "Host: www.example.org:443\r\n" |
| 10323 | "Proxy-Connection: keep-alive\r\n" |
| 10324 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10325 | }; |
| 10326 | MockRead data_reads[] = { |
| 10327 | // Return an error, so the transaction stops here (this test isn't |
| 10328 | // interested in the rest). |
| 10329 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 10330 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10331 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 10332 | }; |
| 10333 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10334 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10335 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10336 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10337 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10338 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10339 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10340 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10341 | |
| 10342 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10343 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 10344 | } |
| 10345 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10346 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10347 | HttpRequestInfo request; |
| 10348 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10349 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 10350 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 10351 | "http://the.previous.site.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10352 | request.traffic_annotation = |
| 10353 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10354 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10355 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10356 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10357 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10358 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10359 | MockWrite( |
| 10360 | "GET / HTTP/1.1\r\n" |
| 10361 | "Host: www.example.org\r\n" |
| 10362 | "Connection: keep-alive\r\n" |
| 10363 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10364 | }; |
| 10365 | |
| 10366 | // Lastly, the server responds with the actual content. |
| 10367 | MockRead data_reads[] = { |
| 10368 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10369 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10370 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10371 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10372 | }; |
| 10373 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10374 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10375 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10376 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10377 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10378 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10379 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10380 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10381 | |
| 10382 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10383 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10384 | } |
| 10385 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10386 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10387 | HttpRequestInfo request; |
| 10388 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10389 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10390 | request.traffic_annotation = |
| 10391 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10392 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10393 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10394 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10395 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10396 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10397 | MockWrite( |
| 10398 | "POST / HTTP/1.1\r\n" |
| 10399 | "Host: www.example.org\r\n" |
| 10400 | "Connection: keep-alive\r\n" |
| 10401 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10402 | }; |
| 10403 | |
| 10404 | // Lastly, the server responds with the actual content. |
| 10405 | MockRead data_reads[] = { |
| 10406 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10407 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10408 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10409 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10410 | }; |
| 10411 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10412 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10413 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10414 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10415 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10416 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10417 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10418 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10419 | |
| 10420 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10421 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10422 | } |
| 10423 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10424 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10425 | HttpRequestInfo request; |
| 10426 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10427 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10428 | request.traffic_annotation = |
| 10429 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10430 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10431 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10432 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10433 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10434 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10435 | MockWrite( |
| 10436 | "PUT / HTTP/1.1\r\n" |
| 10437 | "Host: www.example.org\r\n" |
| 10438 | "Connection: keep-alive\r\n" |
| 10439 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10440 | }; |
| 10441 | |
| 10442 | // Lastly, the server responds with the actual content. |
| 10443 | MockRead data_reads[] = { |
| 10444 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10445 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10446 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10447 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10448 | }; |
| 10449 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10450 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10451 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10452 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10453 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10454 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10455 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10456 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10457 | |
| 10458 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10459 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10460 | } |
| 10461 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10462 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10463 | HttpRequestInfo request; |
| 10464 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10465 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10466 | request.traffic_annotation = |
| 10467 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10468 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10469 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10470 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10471 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10472 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 10473 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 10474 | "Host: www.example.org\r\n" |
| 10475 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10476 | }; |
| 10477 | |
| 10478 | // Lastly, the server responds with the actual content. |
| 10479 | MockRead data_reads[] = { |
| 10480 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10481 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10482 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10483 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10484 | }; |
| 10485 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10486 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10487 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10488 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10489 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10490 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10491 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10492 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10493 | |
| 10494 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10495 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10496 | } |
| 10497 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10498 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10499 | HttpRequestInfo request; |
| 10500 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10501 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10502 | request.load_flags = LOAD_BYPASS_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10503 | request.traffic_annotation = |
| 10504 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10505 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10506 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10507 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10508 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10509 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10510 | MockWrite( |
| 10511 | "GET / HTTP/1.1\r\n" |
| 10512 | "Host: www.example.org\r\n" |
| 10513 | "Connection: keep-alive\r\n" |
| 10514 | "Pragma: no-cache\r\n" |
| 10515 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10516 | }; |
| 10517 | |
| 10518 | // Lastly, the server responds with the actual content. |
| 10519 | MockRead data_reads[] = { |
| 10520 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10521 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10522 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10523 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10524 | }; |
| 10525 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10526 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10527 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10528 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10529 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10530 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10531 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10532 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10533 | |
| 10534 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10535 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10536 | } |
| 10537 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10538 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10539 | HttpRequestInfo request; |
| 10540 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10541 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10542 | request.load_flags = LOAD_VALIDATE_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10543 | request.traffic_annotation = |
| 10544 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10545 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10546 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10547 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10548 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10549 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10550 | MockWrite( |
| 10551 | "GET / HTTP/1.1\r\n" |
| 10552 | "Host: www.example.org\r\n" |
| 10553 | "Connection: keep-alive\r\n" |
| 10554 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10555 | }; |
| 10556 | |
| 10557 | // Lastly, the server responds with the actual content. |
| 10558 | MockRead data_reads[] = { |
| 10559 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10560 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10561 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10562 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10563 | }; |
| 10564 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10565 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10566 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10567 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10568 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10569 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10570 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10571 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10572 | |
| 10573 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10574 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10575 | } |
| 10576 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10577 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10578 | HttpRequestInfo request; |
| 10579 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10580 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10581 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10582 | request.traffic_annotation = |
| 10583 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10584 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10585 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10586 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10587 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10588 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10589 | MockWrite( |
| 10590 | "GET / HTTP/1.1\r\n" |
| 10591 | "Host: www.example.org\r\n" |
| 10592 | "Connection: keep-alive\r\n" |
| 10593 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10594 | }; |
| 10595 | |
| 10596 | // Lastly, the server responds with the actual content. |
| 10597 | MockRead data_reads[] = { |
| 10598 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10599 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10600 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10601 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10602 | }; |
| 10603 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10604 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10605 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10606 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10607 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10608 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10609 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10610 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10611 | |
| 10612 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10613 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 10614 | } |
| 10615 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10616 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10617 | HttpRequestInfo request; |
| 10618 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10619 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 10620 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 10621 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 10622 | request.extra_headers.SetHeader("FoO", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10623 | request.traffic_annotation = |
| 10624 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10625 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10626 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10627 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10628 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10629 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10630 | MockWrite( |
| 10631 | "GET / HTTP/1.1\r\n" |
| 10632 | "Host: www.example.org\r\n" |
| 10633 | "Connection: keep-alive\r\n" |
| 10634 | "referer: www.foo.com\r\n" |
| 10635 | "hEllo: Kitty\r\n" |
| 10636 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10637 | }; |
| 10638 | |
| 10639 | // Lastly, the server responds with the actual content. |
| 10640 | MockRead data_reads[] = { |
| 10641 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10642 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10643 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10644 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10645 | }; |
| 10646 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10647 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10648 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10649 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10650 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10651 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10652 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10653 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10654 | |
| 10655 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10656 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 10657 | } |
| 10658 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10659 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10660 | HttpRequestInfo request; |
| 10661 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10662 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10663 | request.traffic_annotation = |
| 10664 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10665 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10666 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10667 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10668 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10669 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10670 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10671 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10672 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10673 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10674 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10675 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 10676 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10677 | |
| 10678 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10679 | MockWrite(ASYNC, write_buffer, base::size(write_buffer)), |
| 10680 | MockWrite("GET / HTTP/1.1\r\n" |
| 10681 | "Host: www.example.org\r\n" |
| 10682 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10683 | |
| 10684 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10685 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 10686 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10687 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10688 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10689 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10690 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10691 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10692 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10693 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10694 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10695 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10696 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10697 | |
| 10698 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10699 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10700 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10701 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10702 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10703 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10704 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10705 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10706 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10707 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10708 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10709 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10710 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10711 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10712 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10713 | EXPECT_EQ("Payload", response_text); |
| 10714 | } |
| 10715 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10716 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10717 | HttpRequestInfo request; |
| 10718 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10719 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10720 | request.traffic_annotation = |
| 10721 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10722 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10723 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10724 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10725 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10726 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10727 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10728 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10729 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10730 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10731 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10732 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 10733 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10734 | |
| 10735 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10736 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10737 | base::size(write_buffer)), |
| 10738 | MockWrite("GET / HTTP/1.1\r\n" |
| 10739 | "Host: www.example.org\r\n" |
| 10740 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10741 | |
| 10742 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10743 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 10744 | base::size(read_buffer)), |
| 10745 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10746 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10747 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10748 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10749 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10750 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10751 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10752 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10753 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10754 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10755 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10756 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10757 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10758 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10759 | |
| 10760 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10761 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10762 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10763 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10764 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10765 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10766 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10767 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10768 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10769 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10770 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10771 | |
| 10772 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10773 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10774 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10775 | EXPECT_EQ("Payload", response_text); |
| 10776 | } |
| 10777 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10778 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10779 | HttpRequestInfo request; |
| 10780 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10781 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10782 | request.traffic_annotation = |
| 10783 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10784 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10785 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10786 | "socks4://myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10787 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10788 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10789 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10790 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10791 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10792 | |
| 10793 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 10794 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 10795 | |
| 10796 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10797 | MockWrite(ASYNC, write_buffer, 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] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10801 | |
| 10802 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10803 | MockRead(ASYNC, read_buffer, base::size(read_buffer)), |
| 10804 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10805 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10806 | MockRead("Payload"), MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10807 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10808 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10809 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10810 | |
| 10811 | TestCompletionCallback callback; |
| 10812 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10813 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10814 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10815 | |
| 10816 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10817 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10818 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10819 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10820 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10821 | |
| 10822 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10823 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10824 | TestLoadTimingNotReused(load_timing_info, |
| 10825 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10826 | |
| 10827 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10828 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10829 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10830 | EXPECT_EQ("Payload", response_text); |
| 10831 | } |
| 10832 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10833 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10834 | HttpRequestInfo request; |
| 10835 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10836 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10837 | request.traffic_annotation = |
| 10838 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10839 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10840 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10841 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10842 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10843 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10844 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10845 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10846 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10847 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10848 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10849 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 10850 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10851 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10852 | 0x05, // Version |
| 10853 | 0x01, // Command (CONNECT) |
| 10854 | 0x00, // Reserved. |
| 10855 | 0x03, // Address type (DOMAINNAME). |
| 10856 | 0x0F, // Length of domain (15) |
| 10857 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 10858 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10859 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10860 | const char kSOCKS5OkResponse[] = |
| 10861 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 10862 | |
| 10863 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10864 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
| 10865 | MockWrite(ASYNC, kSOCKS5OkRequest, base::size(kSOCKS5OkRequest)), |
| 10866 | MockWrite("GET / HTTP/1.1\r\n" |
| 10867 | "Host: www.example.org\r\n" |
| 10868 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10869 | |
| 10870 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10871 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 10872 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 10873 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10874 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10875 | MockRead("Payload"), |
| 10876 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10877 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10878 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10879 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10880 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10881 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10882 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10883 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10884 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10885 | |
| 10886 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10887 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10888 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10889 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10890 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10891 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10892 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10893 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10894 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10895 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10896 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10897 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10898 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10899 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10900 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10901 | EXPECT_EQ("Payload", response_text); |
| 10902 | } |
| 10903 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10904 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10905 | HttpRequestInfo request; |
| 10906 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10907 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10908 | request.traffic_annotation = |
| 10909 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10910 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10911 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10912 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10913 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10914 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10915 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10916 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10917 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10918 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10919 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10920 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 10921 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10922 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10923 | 0x05, // Version |
| 10924 | 0x01, // Command (CONNECT) |
| 10925 | 0x00, // Reserved. |
| 10926 | 0x03, // Address type (DOMAINNAME). |
| 10927 | 0x0F, // Length of domain (15) |
| 10928 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 10929 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10930 | }; |
| 10931 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10932 | const char kSOCKS5OkResponse[] = |
| 10933 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 10934 | |
| 10935 | MockWrite data_writes[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10936 | MockWrite(ASYNC, kSOCKS5GreetRequest, base::size(kSOCKS5GreetRequest)), |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10937 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10938 | base::size(kSOCKS5OkRequest)), |
| 10939 | MockWrite("GET / HTTP/1.1\r\n" |
| 10940 | "Host: www.example.org\r\n" |
| 10941 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10942 | |
| 10943 | MockRead data_reads[] = { |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 10944 | MockRead(ASYNC, kSOCKS5GreetResponse, base::size(kSOCKS5GreetResponse)), |
| 10945 | MockRead(ASYNC, kSOCKS5OkResponse, base::size(kSOCKS5OkResponse)), |
| 10946 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10947 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10948 | MockRead("Payload"), |
| 10949 | MockRead(SYNCHRONOUS, OK)}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10950 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10951 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10952 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10953 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10954 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10955 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10956 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10957 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10958 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10959 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10960 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10961 | |
| 10962 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10963 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10964 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10965 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10966 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10967 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10968 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10969 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10970 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10971 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10972 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10973 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10974 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10975 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10976 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10977 | EXPECT_EQ("Payload", response_text); |
| 10978 | } |
| 10979 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10980 | namespace { |
| 10981 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10982 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10983 | |
| 10984 | struct GroupNameTest { |
| 10985 | std::string proxy_server; |
| 10986 | std::string url; |
| 10987 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10988 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10989 | }; |
| 10990 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10991 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10992 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10993 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10994 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10995 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10996 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10997 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10998 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10999 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 11000 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11001 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11002 | |
| 11003 | return session; |
| 11004 | } |
| 11005 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11006 | int GroupNameTransactionHelper(const std::string& url, |
| 11007 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11008 | HttpRequestInfo request; |
| 11009 | request.method = "GET"; |
| 11010 | request.url = GURL(url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11011 | request.traffic_annotation = |
| 11012 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11013 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11014 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11015 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11016 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11017 | |
| 11018 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11019 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11020 | } |
| 11021 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 11022 | } // namespace |
| 11023 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11024 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11025 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11026 | { |
| 11027 | "", // unused |
| 11028 | "http://www.example.org/direct", |
| 11029 | "www.example.org:80", |
| 11030 | false, |
| 11031 | }, |
| 11032 | { |
| 11033 | "", // unused |
| 11034 | "http://[2001:1418:13:1::25]/direct", |
| 11035 | "[2001:1418:13:1::25]:80", |
| 11036 | false, |
| 11037 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11038 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11039 | // SSL Tests |
| 11040 | { |
| 11041 | "", // unused |
| 11042 | "https://www.example.org/direct_ssl", |
| 11043 | "ssl/www.example.org:443", |
| 11044 | true, |
| 11045 | }, |
| 11046 | { |
| 11047 | "", // unused |
| 11048 | "https://[2001:1418:13:1::25]/direct", |
| 11049 | "ssl/[2001:1418:13:1::25]:443", |
| 11050 | true, |
| 11051 | }, |
| 11052 | { |
| 11053 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 11054 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11055 | "ssl/host.with.alternate:443", |
| 11056 | true, |
| 11057 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11058 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11059 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11060 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11061 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11062 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11063 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11064 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 11065 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11066 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11067 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11068 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11069 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 11070 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11071 | new CaptureGroupNameSSLSocketPool(nullptr, nullptr); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11072 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 11073 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 11074 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11075 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11076 | |
| 11077 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11078 | GroupNameTransactionHelper(tests[i].url, session.get())); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 11079 | if (tests[i].ssl) { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11080 | EXPECT_EQ(tests[i].expected_group_name, |
| 11081 | ssl_conn_pool->last_group_name_received()); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 11082 | } else { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11083 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 11084 | transport_conn_pool->last_group_name_received()); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 11085 | } |
| 11086 | // When SSL proxy is in use, socket must be requested from |ssl_conn_pool|. |
| 11087 | EXPECT_EQ(tests[i].ssl, ssl_conn_pool->socket_requested()); |
| 11088 | // When SSL proxy is not in use, socket must be requested from |
| 11089 | // |transport_conn_pool|. |
| 11090 | EXPECT_EQ(!tests[i].ssl, transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11091 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11092 | } |
| 11093 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11094 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11095 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11096 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 11097 | "http_proxy", "http://www.example.org/http_proxy_normal", |
| 11098 | "http_proxy/www.example.org:80", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11099 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11100 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11101 | // SSL Tests |
| 11102 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 11103 | "http_proxy", "https://www.example.org/http_connect_ssl", |
| 11104 | "http_proxy/ssl/www.example.org:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11105 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11106 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11107 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 11108 | "http_proxy", "https://host.with.alternate/direct", |
| 11109 | "http_proxy/ssl/host.with.alternate:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11110 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 11111 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11112 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 11113 | "http_proxy", "ftp://ftp.google.com/http_proxy_normal", |
| 11114 | "http_proxy/ftp/ftp.google.com:21", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11115 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11116 | }; |
| 11117 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11118 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11119 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11120 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11121 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11122 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 11123 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11124 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11125 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11126 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11127 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 11128 | HostPortPair("http_proxy", 80)); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 11129 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 11130 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 11131 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 11132 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11133 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 11134 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11135 | proxy_server, base::WrapUnique(http_proxy_pool)); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 11136 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11137 | proxy_server, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11138 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11139 | |
| 11140 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11141 | GroupNameTransactionHelper(tests[i].url, session.get())); |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11142 | if (tests[i].ssl) { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11143 | EXPECT_EQ(tests[i].expected_group_name, |
| 11144 | ssl_conn_pool->last_group_name_received()); |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11145 | } else { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11146 | EXPECT_EQ(tests[i].expected_group_name, |
| 11147 | http_proxy_pool->last_group_name_received()); |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11148 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11149 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11150 | } |
| 11151 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11152 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11153 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11154 | { |
| 11155 | "socks4://socks_proxy:1080", |
| 11156 | "http://www.example.org/socks4_direct", |
| 11157 | "socks4/www.example.org:80", |
| 11158 | false, |
| 11159 | }, |
| 11160 | { |
| 11161 | "socks5://socks_proxy:1080", |
| 11162 | "http://www.example.org/socks5_direct", |
| 11163 | "socks5/www.example.org:80", |
| 11164 | false, |
| 11165 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11166 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11167 | // SSL Tests |
| 11168 | { |
| 11169 | "socks4://socks_proxy:1080", |
| 11170 | "https://www.example.org/socks4_ssl", |
| 11171 | "socks4/ssl/www.example.org:443", |
| 11172 | true, |
| 11173 | }, |
| 11174 | { |
| 11175 | "socks5://socks_proxy:1080", |
| 11176 | "https://www.example.org/socks5_ssl", |
| 11177 | "socks5/ssl/www.example.org:443", |
| 11178 | true, |
| 11179 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 11180 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11181 | { |
| 11182 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 11183 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11184 | "socks4/ssl/host.with.alternate:443", |
| 11185 | true, |
| 11186 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11187 | }; |
| 11188 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 11189 | for (size_t i = 0; i < base::size(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 11190 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11191 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 11192 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11193 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 11194 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 11195 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11196 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11197 | |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11198 | ProxyServer proxy_server( |
| 11199 | ProxyServer::FromURI(tests[i].proxy_server, ProxyServer::SCHEME_HTTP)); |
| 11200 | ASSERT_TRUE(proxy_server.is_valid()); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 11201 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 11202 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 11203 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 11204 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11205 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 11206 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11207 | proxy_server, base::WrapUnique(socks_conn_pool)); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 11208 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
Matt Menke | e8648fa | 2019-01-17 16:47:07 | [diff] [blame] | 11209 | proxy_server, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 11210 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11211 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11212 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11213 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 11214 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 11215 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 11216 | if (tests[i].ssl) |
| 11217 | EXPECT_EQ(tests[i].expected_group_name, |
| 11218 | ssl_conn_pool->last_group_name_received()); |
| 11219 | else |
| 11220 | EXPECT_EQ(tests[i].expected_group_name, |
| 11221 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 11222 | } |
| 11223 | } |
| 11224 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11225 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11226 | HttpRequestInfo request; |
| 11227 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11228 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11229 | request.traffic_annotation = |
| 11230 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11231 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11232 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11233 | "myproxy:70;foobar:80", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11234 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 11235 | // This simulates failure resolving all hostnames; that means we will fail |
| 11236 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11237 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11238 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11239 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11240 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11241 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11242 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11243 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11244 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11245 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11246 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11247 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11248 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 11249 | } |
| 11250 | |
Miriam Gershenson | 2a01b16 | 2018-03-22 22:54:47 | [diff] [blame] | 11251 | // LOAD_BYPASS_CACHE should trigger the host cache bypass. |
| 11252 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11253 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 11254 | HttpRequestInfo request_info; |
| 11255 | request_info.method = "GET"; |
Miriam Gershenson | 2a01b16 | 2018-03-22 22:54:47 | [diff] [blame] | 11256 | request_info.load_flags = LOAD_BYPASS_CACHE; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 11257 | request_info.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11258 | request_info.traffic_annotation = |
| 11259 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11260 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 11261 | // Select a host resolver that does caching. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11262 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 11263 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11264 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11265 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11266 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11267 | // Warm up the host cache so it has an entry for "www.example.org". |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11268 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 11269 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 11270 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11271 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11272 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 11273 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11274 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11275 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 11276 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11277 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11278 | |
| 11279 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 11280 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 11281 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11282 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11283 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 11284 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11285 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11286 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11287 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11288 | // 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] | 11289 | // we can tell if the next lookup hit the cache, or the "network". |
| 11290 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11291 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11292 | |
| 11293 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 11294 | // 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] | 11295 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11296 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11297 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11298 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11299 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11300 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11301 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11302 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11303 | |
| 11304 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11305 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11306 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 11307 | } |
| 11308 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11309 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11310 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11311 | HttpRequestInfo request; |
| 11312 | request.method = "GET"; |
| 11313 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11314 | request.traffic_annotation = |
| 11315 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11316 | |
| 11317 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11318 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11319 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11320 | StaticSocketDataProvider data(base::span<MockRead>(), write_failure); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11321 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11322 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11323 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11324 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11325 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11326 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11327 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11328 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11329 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11330 | |
| 11331 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11332 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11333 | |
| 11334 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11335 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11336 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11337 | } |
| 11338 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11339 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11340 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11341 | HttpRequestInfo request; |
| 11342 | request.method = "GET"; |
| 11343 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11344 | request.traffic_annotation = |
| 11345 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11346 | |
| 11347 | MockRead data_reads[] = { |
| 11348 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11349 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11350 | }; |
| 11351 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11352 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11353 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11354 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11355 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11356 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11357 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11358 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11359 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11360 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11361 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11362 | |
| 11363 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11364 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11365 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11366 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11367 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11368 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11369 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11370 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11371 | |
| 11372 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11373 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11374 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 11375 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11376 | |
| 11377 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11378 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 11379 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11380 | } |
| 11381 | |
| 11382 | // Make sure that a dropped connection while draining the body for auth |
| 11383 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11384 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11385 | HttpRequestInfo request; |
| 11386 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11387 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11388 | request.traffic_annotation = |
| 11389 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11390 | |
| 11391 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11392 | MockWrite( |
| 11393 | "GET / HTTP/1.1\r\n" |
| 11394 | "Host: www.example.org\r\n" |
| 11395 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11396 | }; |
| 11397 | |
| 11398 | MockRead data_reads1[] = { |
| 11399 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 11400 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 11401 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11402 | MockRead("Content-Length: 14\r\n\r\n"), |
| 11403 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11404 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11405 | }; |
| 11406 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11407 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11408 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11409 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11410 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11411 | // be issuing -- the final header line contains the credentials. |
| 11412 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11413 | MockWrite( |
| 11414 | "GET / HTTP/1.1\r\n" |
| 11415 | "Host: www.example.org\r\n" |
| 11416 | "Connection: keep-alive\r\n" |
| 11417 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11418 | }; |
| 11419 | |
| 11420 | // Lastly, the server responds with the actual content. |
| 11421 | MockRead data_reads2[] = { |
| 11422 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11423 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 11424 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11425 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11426 | }; |
| 11427 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11428 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11429 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11430 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11431 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11432 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11433 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11434 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11435 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11436 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11437 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11438 | |
| 11439 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11440 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11441 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11442 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11443 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11444 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11445 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11446 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11447 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11448 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11449 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11450 | |
| 11451 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11452 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11453 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11454 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11455 | ASSERT_TRUE(response); |
| 11456 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11457 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 11458 | } |
| 11459 | |
| 11460 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11461 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 11462 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 11463 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11464 | |
| 11465 | HttpRequestInfo request; |
| 11466 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11467 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11468 | request.traffic_annotation = |
| 11469 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11470 | |
| 11471 | MockRead proxy_reads[] = { |
| 11472 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11473 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11474 | }; |
| 11475 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11476 | StaticSocketDataProvider data(proxy_reads, base::span<MockWrite>()); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11477 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11478 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11479 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11480 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11481 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11482 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11483 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11484 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11485 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11486 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11487 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11488 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11489 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11490 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11491 | |
| 11492 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11493 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 11494 | } |
| 11495 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11496 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11497 | HttpRequestInfo request; |
| 11498 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11499 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11500 | request.traffic_annotation = |
| 11501 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11502 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11503 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11504 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 11505 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11506 | MockRead data_reads[] = { |
| 11507 | 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] | 11508 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11509 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11510 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11511 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11512 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11513 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11514 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11515 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11516 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11517 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11518 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11519 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11520 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11521 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11522 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11523 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11524 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 11525 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 11526 | |
| 11527 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11528 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11529 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 11530 | } |
| 11531 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11532 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11533 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11534 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11535 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 11536 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 11537 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11538 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11539 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11540 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11541 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11542 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11543 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11544 | |
| 11545 | HttpRequestInfo request; |
| 11546 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11547 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11548 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11549 | request.traffic_annotation = |
| 11550 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11551 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11552 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11553 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11554 | |
| 11555 | MockRead data_reads[] = { |
| 11556 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 11557 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11558 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11559 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11560 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11561 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11562 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11563 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11564 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11565 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11566 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11567 | |
| 11568 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11569 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11570 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11571 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11572 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11573 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 11574 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11575 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11576 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 11577 | } |
| 11578 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11579 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 11580 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 11581 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11582 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 11583 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 11584 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 11585 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 11586 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11587 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11588 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11589 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11590 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 11591 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11592 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11593 | |
| 11594 | HttpRequestInfo request; |
| 11595 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11596 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11597 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11598 | request.traffic_annotation = |
| 11599 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 11600 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 11601 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11602 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11603 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11604 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11605 | StaticSocketDataProvider data; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11606 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11607 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11608 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11609 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11610 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11611 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11612 | |
| 11613 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11614 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11615 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 11616 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 11617 | } |
| 11618 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11619 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11620 | class FakeUploadElementReader : public UploadElementReader { |
| 11621 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 11622 | FakeUploadElementReader() = default; |
| 11623 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11624 | |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11625 | CompletionOnceCallback TakeCallback() { return std::move(callback_); } |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11626 | |
| 11627 | // UploadElementReader overrides: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11628 | int Init(CompletionOnceCallback callback) override { |
| 11629 | callback_ = std::move(callback); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11630 | return ERR_IO_PENDING; |
| 11631 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 11632 | uint64_t GetContentLength() const override { return 0; } |
| 11633 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 11634 | int Read(IOBuffer* buf, |
| 11635 | int buf_length, |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11636 | CompletionOnceCallback callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11637 | return ERR_FAILED; |
| 11638 | } |
| 11639 | |
| 11640 | private: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11641 | CompletionOnceCallback callback_; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11642 | }; |
| 11643 | |
| 11644 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11645 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 11646 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 11647 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11648 | |
| 11649 | HttpRequestInfo request; |
| 11650 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11651 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11652 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11653 | request.traffic_annotation = |
| 11654 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11655 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11656 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11657 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11658 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11659 | |
| 11660 | StaticSocketDataProvider data; |
| 11661 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11662 | |
| 11663 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11664 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11665 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 11666 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11667 | |
| 11668 | // Transaction is pending on request body initialization. |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11669 | CompletionOnceCallback init_callback = fake_reader->TakeCallback(); |
| 11670 | ASSERT_FALSE(init_callback.is_null()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11671 | |
| 11672 | // Return Init()'s result after the transaction gets destroyed. |
| 11673 | trans.reset(); |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 11674 | std::move(init_callback).Run(OK); // Should not crash. |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 11675 | } |
| 11676 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11677 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11678 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11679 | HttpRequestInfo request; |
| 11680 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11681 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11682 | request.traffic_annotation = |
| 11683 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11684 | |
| 11685 | // First transaction will request a resource and receive a Basic challenge |
| 11686 | // with realm="first_realm". |
| 11687 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11688 | MockWrite( |
| 11689 | "GET / HTTP/1.1\r\n" |
| 11690 | "Host: www.example.org\r\n" |
| 11691 | "Connection: keep-alive\r\n" |
| 11692 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11693 | }; |
| 11694 | MockRead data_reads1[] = { |
| 11695 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11696 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11697 | "\r\n"), |
| 11698 | }; |
| 11699 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11700 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11701 | // for first_realm. The server will reject and provide a challenge with |
| 11702 | // second_realm. |
| 11703 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11704 | MockWrite( |
| 11705 | "GET / HTTP/1.1\r\n" |
| 11706 | "Host: www.example.org\r\n" |
| 11707 | "Connection: keep-alive\r\n" |
| 11708 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 11709 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11710 | }; |
| 11711 | MockRead data_reads2[] = { |
| 11712 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11713 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 11714 | "\r\n"), |
| 11715 | }; |
| 11716 | |
| 11717 | // This again fails, and goes back to first_realm. Make sure that the |
| 11718 | // entry is removed from cache. |
| 11719 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11720 | MockWrite( |
| 11721 | "GET / HTTP/1.1\r\n" |
| 11722 | "Host: www.example.org\r\n" |
| 11723 | "Connection: keep-alive\r\n" |
| 11724 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 11725 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11726 | }; |
| 11727 | MockRead data_reads3[] = { |
| 11728 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 11729 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 11730 | "\r\n"), |
| 11731 | }; |
| 11732 | |
| 11733 | // Try one last time (with the correct password) and get the resource. |
| 11734 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11735 | MockWrite( |
| 11736 | "GET / HTTP/1.1\r\n" |
| 11737 | "Host: www.example.org\r\n" |
| 11738 | "Connection: keep-alive\r\n" |
| 11739 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 11740 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11741 | }; |
| 11742 | MockRead data_reads4[] = { |
| 11743 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11744 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11745 | "Content-Length: 5\r\n" |
| 11746 | "\r\n" |
| 11747 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11748 | }; |
| 11749 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11750 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 11751 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 11752 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
| 11753 | StaticSocketDataProvider data4(data_reads4, data_writes4); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11754 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 11755 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 11756 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 11757 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11758 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11759 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11760 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11761 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11762 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 11763 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11764 | // Issue the first request with Authorize headers. There should be a |
| 11765 | // password prompt for first_realm waiting to be filled in after the |
| 11766 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11767 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11768 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11769 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11770 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11771 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11772 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11773 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11774 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11775 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11776 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11777 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11778 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11779 | |
| 11780 | // Issue the second request with an incorrect password. There should be a |
| 11781 | // password prompt for second_realm waiting to be filled in after the |
| 11782 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11783 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11784 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 11785 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11786 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11787 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11788 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11789 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11790 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11791 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11792 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11793 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11794 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11795 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11796 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11797 | |
| 11798 | // Issue the third request with another incorrect password. There should be |
| 11799 | // a password prompt for first_realm waiting to be filled in. If the password |
| 11800 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 11801 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11802 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11803 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 11804 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11805 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11806 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11807 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11808 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11809 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11810 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11811 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11812 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 11813 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 11814 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 11815 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11816 | |
| 11817 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11818 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11819 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 11820 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11821 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11822 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11823 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11824 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11825 | ASSERT_TRUE(response); |
| 11826 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11827 | } |
| 11828 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11829 | // Regression test for https://crbug.com/754395. |
| 11830 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 11831 | MockRead data_reads[] = { |
| 11832 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11833 | MockRead(kAlternativeServiceHttpHeader), |
| 11834 | MockRead("\r\n"), |
| 11835 | MockRead("hello world"), |
| 11836 | MockRead(SYNCHRONOUS, OK), |
| 11837 | }; |
| 11838 | |
| 11839 | HttpRequestInfo request; |
| 11840 | request.method = "GET"; |
| 11841 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11842 | request.traffic_annotation = |
| 11843 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11844 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11845 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11846 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11847 | |
| 11848 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11849 | ssl.ssl_info.cert = |
| 11850 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11851 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 11852 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11853 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11854 | |
| 11855 | TestCompletionCallback callback; |
| 11856 | |
| 11857 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11858 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11859 | |
| 11860 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 11861 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11862 | |
| 11863 | url::SchemeHostPort test_server(request.url); |
| 11864 | HttpServerProperties* http_server_properties = |
| 11865 | session->http_server_properties(); |
| 11866 | EXPECT_TRUE( |
| 11867 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11868 | |
| 11869 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11870 | |
| 11871 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11872 | ASSERT_TRUE(response); |
| 11873 | ASSERT_TRUE(response->headers); |
| 11874 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11875 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11876 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 11877 | |
| 11878 | std::string response_data; |
| 11879 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11880 | EXPECT_EQ("hello world", response_data); |
| 11881 | |
| 11882 | EXPECT_TRUE( |
| 11883 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11884 | } |
| 11885 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11886 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11887 | MockRead data_reads[] = { |
| 11888 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11889 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11890 | MockRead("\r\n"), |
| 11891 | MockRead("hello world"), |
| 11892 | MockRead(SYNCHRONOUS, OK), |
| 11893 | }; |
| 11894 | |
| 11895 | HttpRequestInfo request; |
| 11896 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11897 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11898 | request.traffic_annotation = |
| 11899 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11900 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11901 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11902 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11903 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11904 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11905 | ssl.ssl_info.cert = |
| 11906 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11907 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11908 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11909 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11910 | TestCompletionCallback callback; |
| 11911 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11912 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11913 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11914 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11915 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11916 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11917 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11918 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11919 | HttpServerProperties* http_server_properties = |
| 11920 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11921 | EXPECT_TRUE( |
| 11922 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11923 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11924 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11925 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11926 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11927 | ASSERT_TRUE(response); |
| 11928 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11929 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11930 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11931 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11932 | |
| 11933 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11934 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11935 | EXPECT_EQ("hello world", response_data); |
| 11936 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11937 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 11938 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 11939 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 11940 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 11941 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11942 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11943 | } |
| 11944 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11945 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11946 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11947 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11948 | MockRead data_reads[] = { |
| 11949 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11950 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11951 | MockRead("\r\n"), |
| 11952 | MockRead("hello world"), |
| 11953 | MockRead(SYNCHRONOUS, OK), |
| 11954 | }; |
| 11955 | |
| 11956 | HttpRequestInfo request; |
| 11957 | request.method = "GET"; |
| 11958 | request.url = GURL("http://www.example.org/"); |
| 11959 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11960 | request.traffic_annotation = |
| 11961 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11962 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11963 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11964 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11965 | |
| 11966 | TestCompletionCallback callback; |
| 11967 | |
| 11968 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11969 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11970 | |
| 11971 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11972 | HttpServerProperties* http_server_properties = |
| 11973 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11974 | EXPECT_TRUE( |
| 11975 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11976 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11977 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11978 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11979 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11980 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11981 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11982 | ASSERT_TRUE(response); |
| 11983 | ASSERT_TRUE(response->headers); |
| 11984 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11985 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11986 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11987 | |
| 11988 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11989 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11990 | EXPECT_EQ("hello world", response_data); |
| 11991 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11992 | EXPECT_TRUE( |
| 11993 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11994 | } |
| 11995 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 11996 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11997 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11998 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11999 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 12000 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12001 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12002 | HttpRequestInfo request; |
| 12003 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12004 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12005 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12006 | request.traffic_annotation = |
| 12007 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12008 | |
| 12009 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12010 | StaticSocketDataProvider first_data; |
| 12011 | first_data.set_connect_data(mock_connect); |
| 12012 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12013 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12014 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12015 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12016 | |
| 12017 | MockRead data_reads[] = { |
| 12018 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12019 | MockRead(ASYNC, OK), |
| 12020 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12021 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12022 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12023 | |
| 12024 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12025 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12026 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12027 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12028 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 12029 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12030 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12031 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12032 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 12033 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12034 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12035 | TestCompletionCallback callback; |
| 12036 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12037 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12038 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12039 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12040 | } |
| 12041 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12042 | // Regression test for https://crbug.com/615497: |
| 12043 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12044 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12045 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12046 | HttpRequestInfo request; |
| 12047 | request.method = "GET"; |
| 12048 | request.url = GURL("http://www.example.org/"); |
| 12049 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12050 | request.traffic_annotation = |
| 12051 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12052 | |
| 12053 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12054 | StaticSocketDataProvider first_data; |
| 12055 | first_data.set_connect_data(mock_connect); |
| 12056 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 12057 | |
| 12058 | MockRead data_reads[] = { |
| 12059 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 12060 | MockRead(ASYNC, OK), |
| 12061 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12062 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12063 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 12064 | |
| 12065 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12066 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12067 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12068 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12069 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12070 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12071 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12072 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 12073 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12074 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12075 | TestCompletionCallback callback; |
| 12076 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12077 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12078 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12079 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 12080 | } |
| 12081 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12082 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12083 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12084 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12085 | HttpServerProperties* http_server_properties = |
| 12086 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12087 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12088 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12089 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12090 | http_server_properties->SetQuicAlternativeService( |
| 12091 | test_server, alternative_service, expiration, |
| 12092 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12093 | EXPECT_EQ( |
| 12094 | 1u, |
| 12095 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12096 | |
| 12097 | // Send a clear header. |
| 12098 | MockRead data_reads[] = { |
| 12099 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 12100 | MockRead("Alt-Svc: clear\r\n"), |
| 12101 | MockRead("\r\n"), |
| 12102 | MockRead("hello world"), |
| 12103 | MockRead(SYNCHRONOUS, OK), |
| 12104 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12105 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12106 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12107 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12108 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12109 | ssl.ssl_info.cert = |
| 12110 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12111 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12112 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12113 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12114 | HttpRequestInfo request; |
| 12115 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12116 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12117 | request.traffic_annotation = |
| 12118 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12119 | |
| 12120 | TestCompletionCallback callback; |
| 12121 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12122 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12123 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12124 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12125 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12126 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12127 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12128 | ASSERT_TRUE(response); |
| 12129 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12130 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12131 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12132 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12133 | |
| 12134 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12135 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12136 | EXPECT_EQ("hello world", response_data); |
| 12137 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12138 | EXPECT_TRUE( |
| 12139 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 12140 | } |
| 12141 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12142 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12143 | MockRead data_reads[] = { |
| 12144 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12145 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 12146 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12147 | MockRead("hello world"), |
| 12148 | MockRead(SYNCHRONOUS, OK), |
| 12149 | }; |
| 12150 | |
| 12151 | HttpRequestInfo request; |
| 12152 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12153 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12154 | request.traffic_annotation = |
| 12155 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12156 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12157 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12158 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 12159 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12160 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12161 | ssl.ssl_info.cert = |
| 12162 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12163 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12164 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12165 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12166 | TestCompletionCallback callback; |
| 12167 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12168 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12169 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12170 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12171 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12172 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12173 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12174 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12175 | HttpServerProperties* http_server_properties = |
| 12176 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12177 | EXPECT_TRUE( |
| 12178 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12179 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12180 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12181 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12182 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12183 | ASSERT_TRUE(response); |
| 12184 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12185 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12186 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12187 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12188 | |
| 12189 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12190 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12191 | EXPECT_EQ("hello world", response_data); |
| 12192 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12193 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 12194 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 12195 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 12196 | |
| 12197 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 12198 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12199 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12200 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 12201 | 1234); |
| 12202 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12203 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12204 | } |
| 12205 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12206 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12207 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12208 | HostPortPair alternative("alternative.example.org", 443); |
| 12209 | std::string origin_url = "https://origin.example.org:443"; |
| 12210 | std::string alternative_url = "https://alternative.example.org:443"; |
| 12211 | |
| 12212 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 12213 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12214 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12215 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12216 | |
| 12217 | // HTTP/1.1 data for request. |
| 12218 | MockWrite http_writes[] = { |
| 12219 | MockWrite("GET / HTTP/1.1\r\n" |
| 12220 | "Host: alternative.example.org\r\n" |
| 12221 | "Connection: keep-alive\r\n\r\n"), |
| 12222 | }; |
| 12223 | |
| 12224 | MockRead http_reads[] = { |
| 12225 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12226 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12227 | "Content-Length: 40\r\n\r\n" |
| 12228 | "first HTTP/1.1 response from alternative"), |
| 12229 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12230 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12231 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12232 | |
| 12233 | StaticSocketDataProvider data_refused; |
| 12234 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12235 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12236 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12237 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12238 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12239 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12240 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12241 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12242 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12243 | http_server_properties->SetQuicAlternativeService( |
| 12244 | server, alternative_service, expiration, |
| 12245 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12246 | // Mark the QUIC alternative service as broken. |
| 12247 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 12248 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12249 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12250 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12251 | request.method = "GET"; |
| 12252 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12253 | request.traffic_annotation = |
| 12254 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12255 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12256 | TestCompletionCallback callback; |
| 12257 | NetErrorDetails details; |
| 12258 | EXPECT_FALSE(details.quic_broken); |
| 12259 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12260 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12261 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12262 | EXPECT_TRUE(details.quic_broken); |
| 12263 | } |
| 12264 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12265 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12266 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12267 | HostPortPair alternative1("alternative1.example.org", 443); |
| 12268 | HostPortPair alternative2("alternative2.example.org", 443); |
| 12269 | std::string origin_url = "https://origin.example.org:443"; |
| 12270 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 12271 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 12272 | |
| 12273 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 12274 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12275 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12276 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12277 | |
| 12278 | // HTTP/1.1 data for request. |
| 12279 | MockWrite http_writes[] = { |
| 12280 | MockWrite("GET / HTTP/1.1\r\n" |
| 12281 | "Host: alternative1.example.org\r\n" |
| 12282 | "Connection: keep-alive\r\n\r\n"), |
| 12283 | }; |
| 12284 | |
| 12285 | MockRead http_reads[] = { |
| 12286 | MockRead("HTTP/1.1 200 OK\r\n" |
| 12287 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12288 | "Content-Length: 40\r\n\r\n" |
| 12289 | "first HTTP/1.1 response from alternative1"), |
| 12290 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12291 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12292 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 12293 | |
| 12294 | StaticSocketDataProvider data_refused; |
| 12295 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 12296 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 12297 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12298 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12299 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12300 | session->http_server_properties(); |
| 12301 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12302 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12303 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 12304 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 12305 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12306 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12307 | alternative_service_info_vector.push_back( |
| 12308 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12309 | alternative_service1, expiration, |
| 12310 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12311 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12312 | alternative_service_info_vector.push_back( |
| 12313 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 12314 | alternative_service2, expiration, |
| 12315 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12316 | |
| 12317 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12318 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12319 | |
| 12320 | // Mark one of the QUIC alternative service as broken. |
| 12321 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12322 | EXPECT_EQ(2u, |
| 12323 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12324 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12325 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 12326 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12327 | request.method = "GET"; |
| 12328 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12329 | request.traffic_annotation = |
| 12330 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 12331 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12332 | TestCompletionCallback callback; |
| 12333 | NetErrorDetails details; |
| 12334 | EXPECT_FALSE(details.quic_broken); |
| 12335 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12336 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12337 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 12338 | EXPECT_FALSE(details.quic_broken); |
| 12339 | } |
| 12340 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12341 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12342 | HttpRequestInfo request; |
| 12343 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12344 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12345 | request.traffic_annotation = |
| 12346 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12347 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12348 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12349 | StaticSocketDataProvider first_data; |
| 12350 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12351 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12352 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12353 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12354 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12355 | |
| 12356 | MockRead data_reads[] = { |
| 12357 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12358 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12359 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12360 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12361 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12362 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12363 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12364 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12365 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12366 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12367 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12368 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12369 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 12370 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12371 | // Port is ignored by MockConnect anyway. |
| 12372 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12373 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12374 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12375 | http_server_properties->SetHttp2AlternativeService( |
| 12376 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12377 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12378 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12379 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12380 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12381 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12382 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12383 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12384 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12385 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12386 | ASSERT_TRUE(response); |
| 12387 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12388 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12389 | |
| 12390 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12391 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12392 | EXPECT_EQ("hello world", response_data); |
| 12393 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12394 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 12395 | http_server_properties->GetAlternativeServiceInfos(server); |
| 12396 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 12397 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 12398 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 12399 | EXPECT_TRUE( |
| 12400 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12401 | } |
| 12402 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12403 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12404 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12405 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12406 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12407 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12408 | HttpRequestInfo restricted_port_request; |
| 12409 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12410 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12411 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12412 | restricted_port_request.traffic_annotation = |
| 12413 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12414 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12415 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12416 | StaticSocketDataProvider first_data; |
| 12417 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12418 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12419 | |
| 12420 | MockRead data_reads[] = { |
| 12421 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12422 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12423 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12424 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12425 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12426 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12427 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12428 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12429 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12430 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12431 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12432 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12433 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12434 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12435 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12436 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12437 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12438 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12439 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12440 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12441 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12442 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12443 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12444 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12445 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12446 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12447 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12448 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12449 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12450 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12451 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12452 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12453 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 12454 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 12455 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12456 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12457 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12458 | |
| 12459 | HttpRequestInfo restricted_port_request; |
| 12460 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12461 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12462 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12463 | restricted_port_request.traffic_annotation = |
| 12464 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12465 | |
| 12466 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 12467 | StaticSocketDataProvider first_data; |
| 12468 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12469 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12470 | |
| 12471 | MockRead data_reads[] = { |
| 12472 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12473 | MockRead("hello world"), |
| 12474 | MockRead(ASYNC, OK), |
| 12475 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12476 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12477 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12478 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12479 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12480 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12481 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12482 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12483 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12484 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12485 | session->http_server_properties(); |
| 12486 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12487 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12488 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12489 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12490 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12491 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12492 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12493 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12494 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12495 | TestCompletionCallback callback; |
| 12496 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12497 | EXPECT_EQ(ERR_IO_PENDING, |
| 12498 | trans.Start(&restricted_port_request, callback.callback(), |
| 12499 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 12500 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12501 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12502 | } |
| 12503 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12504 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12505 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12506 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12507 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12508 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12509 | HttpRequestInfo restricted_port_request; |
| 12510 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12511 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12512 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12513 | restricted_port_request.traffic_annotation = |
| 12514 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12515 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12516 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12517 | StaticSocketDataProvider first_data; |
| 12518 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12519 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12520 | |
| 12521 | MockRead data_reads[] = { |
| 12522 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12523 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12524 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12525 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12526 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12527 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12528 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12529 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12530 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12531 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12532 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12533 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12534 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12535 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12536 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12537 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12538 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12539 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12540 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12541 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12542 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12543 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12544 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12545 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12546 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12547 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 12548 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12549 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12550 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12551 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12552 | } |
| 12553 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12554 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12555 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12556 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12557 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12558 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12559 | HttpRequestInfo unrestricted_port_request; |
| 12560 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12561 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12562 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12563 | unrestricted_port_request.traffic_annotation = |
| 12564 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12565 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12566 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12567 | StaticSocketDataProvider first_data; |
| 12568 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12569 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12570 | |
| 12571 | MockRead data_reads[] = { |
| 12572 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12573 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12574 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12575 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12576 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12577 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12578 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12579 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12580 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12581 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12582 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12583 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12584 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12585 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12586 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12587 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12588 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12589 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12590 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12591 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12592 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12593 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12594 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12595 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12596 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12597 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12598 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12599 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12600 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12601 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12602 | } |
| 12603 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12604 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 12605 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 12606 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 12607 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12608 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12609 | HttpRequestInfo unrestricted_port_request; |
| 12610 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12611 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12612 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12613 | unrestricted_port_request.traffic_annotation = |
| 12614 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12615 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12616 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12617 | StaticSocketDataProvider first_data; |
| 12618 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12619 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12620 | |
| 12621 | MockRead data_reads[] = { |
| 12622 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12623 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12624 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12625 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12626 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12627 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12628 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12629 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 12630 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 12631 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12632 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12633 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12634 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 12635 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 12636 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12637 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12638 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12639 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12640 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12641 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 12642 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12643 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12644 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12645 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12646 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12647 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12648 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12649 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12650 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12651 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 12652 | } |
| 12653 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 12654 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
Xida Chen | 9bfe0b6 | 2018-04-24 19:52:21 | [diff] [blame] | 12655 | // to an unsafe port, and that we resume the second HttpStreamFactory::Job once |
| 12656 | // the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12657 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12658 | HttpRequestInfo request; |
| 12659 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12660 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12661 | request.traffic_annotation = |
| 12662 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12663 | |
| 12664 | // The alternate protocol request will error out before we attempt to connect, |
| 12665 | // so only the standard HTTP request will try to connect. |
| 12666 | MockRead data_reads[] = { |
| 12667 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 12668 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12669 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12670 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12671 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12672 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12673 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12674 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12675 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 12676 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12677 | session->http_server_properties(); |
| 12678 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12679 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 12680 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 12681 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12682 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 12683 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12684 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12685 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12686 | TestCompletionCallback callback; |
| 12687 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12688 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12689 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12690 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12691 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12692 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12693 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12694 | ASSERT_TRUE(response); |
| 12695 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12696 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12697 | |
| 12698 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 12699 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 12700 | EXPECT_EQ("hello world", response_data); |
| 12701 | } |
| 12702 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12703 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12704 | HttpRequestInfo request; |
| 12705 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12706 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12707 | request.traffic_annotation = |
| 12708 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12709 | |
| 12710 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12711 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12712 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12713 | MockRead("\r\n"), |
| 12714 | MockRead("hello world"), |
| 12715 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12716 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12717 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12718 | StaticSocketDataProvider first_transaction(data_reads, |
| 12719 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12720 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12721 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12722 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12723 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12724 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12725 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12726 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12727 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12728 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12729 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12730 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12731 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 12732 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12733 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12734 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12735 | }; |
| 12736 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12737 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12738 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12739 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12740 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12741 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12742 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12743 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12744 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12745 | &hanging_non_alternate_protocol_socket); |
| 12746 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12747 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12748 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12749 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12750 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12751 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12752 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12753 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12754 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12755 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12756 | |
| 12757 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12758 | ASSERT_TRUE(response); |
| 12759 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12760 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12761 | |
| 12762 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12763 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12764 | EXPECT_EQ("hello world", response_data); |
| 12765 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12766 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12767 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12768 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12769 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12770 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12771 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12772 | |
| 12773 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12774 | ASSERT_TRUE(response); |
| 12775 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12776 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12777 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12778 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12779 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12780 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12781 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12782 | } |
| 12783 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12784 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12785 | HttpRequestInfo request; |
| 12786 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12787 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12788 | request.traffic_annotation = |
| 12789 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12790 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12791 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12792 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12793 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12794 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12795 | MockRead("\r\n"), |
| 12796 | MockRead("hello world"), |
| 12797 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12798 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12799 | }; |
| 12800 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12801 | StaticSocketDataProvider http11_data(data_reads, base::span<MockWrite>()); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12802 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12803 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12804 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12805 | ssl_http11.ssl_info.cert = |
| 12806 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12807 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12808 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 12809 | |
| 12810 | // Second transaction starts an alternative and a non-alternative Job. |
| 12811 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12812 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12813 | StaticSocketDataProvider hanging_socket1; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12814 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12815 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 12816 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12817 | StaticSocketDataProvider hanging_socket2; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12818 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 12819 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12820 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12821 | // Third transaction starts an alternative and a non-alternative job. |
| 12822 | // The non-alternative job hangs, but the alternative one succeeds. |
| 12823 | // The second transaction, still pending, binds to this socket. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12824 | spdy::SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12825 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12826 | spdy::SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12827 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12828 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12829 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12830 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12831 | spdy::SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 12832 | spdy::SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 12833 | spdy::SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 12834 | spdy::SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12835 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12836 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 12837 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12838 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12839 | }; |
| 12840 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12841 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12842 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12843 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12844 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12845 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12846 | StaticSocketDataProvider hanging_socket3; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12847 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 12848 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12849 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12850 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12851 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12852 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12853 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12854 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12855 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12856 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12857 | |
| 12858 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12859 | ASSERT_TRUE(response); |
| 12860 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12861 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12862 | |
| 12863 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12864 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12865 | EXPECT_EQ("hello world", response_data); |
| 12866 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12867 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12868 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12869 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12870 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12871 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12872 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12873 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12874 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12875 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12876 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12877 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 12878 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12879 | |
| 12880 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12881 | ASSERT_TRUE(response); |
| 12882 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12883 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12884 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12885 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12886 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12887 | EXPECT_EQ("hello!", response_data); |
| 12888 | |
| 12889 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12890 | ASSERT_TRUE(response); |
| 12891 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12892 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12893 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12894 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12895 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12896 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12897 | } |
| 12898 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12899 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
Bence Béky | bcae3709 | 2018-06-12 04:18:53 | [diff] [blame] | 12900 | session_deps_.host_resolver->set_synchronous_mode(true); |
| 12901 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12902 | HttpRequestInfo request; |
| 12903 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12904 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12905 | request.traffic_annotation = |
| 12906 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12907 | |
| 12908 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12909 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12910 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12911 | MockRead("\r\n"), |
| 12912 | MockRead("hello world"), |
| 12913 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12914 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12915 | }; |
| 12916 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12917 | StaticSocketDataProvider first_transaction(data_reads, |
| 12918 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12919 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12920 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12921 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12922 | ssl.ssl_info.cert = |
| 12923 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12924 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12925 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12926 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12927 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12928 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12929 | hanging_alternate_protocol_socket.set_connect_data( |
| 12930 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12931 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12932 | &hanging_alternate_protocol_socket); |
| 12933 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12934 | // 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] | 12935 | StaticSocketDataProvider second_transaction(data_reads, |
| 12936 | base::span<MockWrite>()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12937 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12938 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12939 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12940 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12941 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12942 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12943 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12944 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12945 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12946 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12947 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12948 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12949 | |
| 12950 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12951 | ASSERT_TRUE(response); |
| 12952 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12953 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12954 | |
| 12955 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12956 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12957 | EXPECT_EQ("hello world", response_data); |
| 12958 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12959 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12960 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12961 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12962 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12963 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12964 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12965 | |
| 12966 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12967 | ASSERT_TRUE(response); |
| 12968 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12969 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12970 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12971 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12972 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12973 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12974 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12975 | } |
| 12976 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12977 | // Test that proxy is resolved using the origin url, |
| 12978 | // regardless of the alternative server. |
| 12979 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 12980 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 12981 | ProxyConfig proxy_config; |
| 12982 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 12983 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 12984 | auto proxy_config_service = std::make_unique<ProxyConfigServiceFixed>( |
| 12985 | ProxyConfigWithAnnotation(proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12986 | |
| 12987 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12988 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12989 | &capturing_proxy_resolver); |
| 12990 | |
| 12991 | TestNetLog net_log; |
| 12992 | |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 12993 | session_deps_.proxy_resolution_service = |
| 12994 | std::make_unique<ProxyResolutionService>( |
| 12995 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 12996 | &net_log); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12997 | |
| 12998 | session_deps_.net_log = &net_log; |
| 12999 | |
| 13000 | // Configure alternative service with a hostname that is not bypassed by the |
| 13001 | // proxy. |
| 13002 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 13003 | HttpServerProperties* http_server_properties = |
| 13004 | session->http_server_properties(); |
| 13005 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 13006 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 13007 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13008 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 13009 | http_server_properties->SetHttp2AlternativeService( |
| 13010 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13011 | |
| 13012 | // Non-alternative job should hang. |
| 13013 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13014 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13015 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 13016 | session_deps_.socket_factory->AddSocketDataProvider( |
| 13017 | &hanging_alternate_protocol_socket); |
| 13018 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13019 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13020 | |
| 13021 | HttpRequestInfo request; |
| 13022 | request.method = "GET"; |
| 13023 | request.url = GURL("https://www.example.org/"); |
| 13024 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13025 | request.traffic_annotation = |
| 13026 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13027 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13028 | spdy::SpdySerializedFrame req( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13029 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 13030 | |
| 13031 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 13032 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13033 | spdy::SpdySerializedFrame resp( |
| 13034 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 13035 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13036 | MockRead spdy_reads[] = { |
| 13037 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 13038 | }; |
| 13039 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13040 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13041 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 13042 | |
| 13043 | TestCompletionCallback callback; |
| 13044 | |
| 13045 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13046 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13047 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13048 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 13049 | |
| 13050 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 13051 | ASSERT_TRUE(response); |
| 13052 | ASSERT_TRUE(response->headers); |
| 13053 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 13054 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13055 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 13056 | |
| 13057 | std::string response_data; |
| 13058 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 13059 | EXPECT_EQ("hello!", response_data); |
| 13060 | |
| 13061 | // Origin host bypasses proxy, no resolution should have happened. |
| 13062 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 13063 | } |
| 13064 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13065 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13066 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13067 | proxy_config.set_auto_detect(true); |
| 13068 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 13069 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13070 | CapturingProxyResolver capturing_proxy_resolver; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13071 | session_deps_.proxy_resolution_service = |
| 13072 | std::make_unique<ProxyResolutionService>( |
| 13073 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 13074 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 13075 | std::make_unique<CapturingProxyResolverFactory>( |
| 13076 | &capturing_proxy_resolver), |
| 13077 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13078 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13079 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13080 | |
| 13081 | HttpRequestInfo request; |
| 13082 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13083 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13084 | request.traffic_annotation = |
| 13085 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13086 | |
| 13087 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13088 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13089 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13090 | MockRead("\r\n"), |
| 13091 | MockRead("hello world"), |
| 13092 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 13093 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13094 | }; |
| 13095 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13096 | StaticSocketDataProvider first_transaction(data_reads, |
| 13097 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13098 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13099 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13100 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13101 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13102 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13103 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13104 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13105 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13106 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13107 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13108 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13109 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13110 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 13111 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13112 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13113 | }; |
| 13114 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 13115 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 13116 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13117 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 13118 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13119 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13120 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 13121 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13122 | }; |
| 13123 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13124 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13125 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13126 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13127 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13128 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13129 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 13130 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13131 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 13132 | &hanging_non_alternate_protocol_socket); |
| 13133 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13134 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13135 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13136 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13137 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13138 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13139 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13140 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13141 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13142 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 13143 | |
| 13144 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 13145 | ASSERT_TRUE(response); |
| 13146 | ASSERT_TRUE(response->headers); |
| 13147 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 13148 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13149 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13150 | |
| 13151 | std::string response_data; |
| 13152 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 13153 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13154 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13155 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13156 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13157 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13158 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13159 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13160 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13161 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 13162 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13163 | ASSERT_TRUE(response); |
| 13164 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13165 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13166 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13167 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13168 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13169 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13170 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13171 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 13172 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13173 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13174 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 13175 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13176 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13177 | LoadTimingInfo load_timing_info; |
| 13178 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 13179 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13180 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13181 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 13182 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13183 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 13184 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13185 | HttpRequestInfo request; |
| 13186 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13187 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13188 | request.traffic_annotation = |
| 13189 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13190 | |
| 13191 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13192 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13193 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13194 | MockRead("\r\n"), |
| 13195 | MockRead("hello world"), |
| 13196 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13197 | }; |
| 13198 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13199 | StaticSocketDataProvider first_transaction(data_reads, |
| 13200 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13201 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13202 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13203 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13204 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13205 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 13206 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13207 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13208 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 13209 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13210 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13211 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13212 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 13213 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13214 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13215 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13216 | }; |
| 13217 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13218 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13219 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13220 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 13221 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13222 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13223 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13224 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13225 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13226 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13227 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13228 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13229 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13230 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13231 | |
| 13232 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13233 | ASSERT_TRUE(response); |
| 13234 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13235 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13236 | |
| 13237 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13238 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13239 | EXPECT_EQ("hello world", response_data); |
| 13240 | |
| 13241 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 13242 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 13243 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 13244 | PRIVACY_MODE_DISABLED, |
| 13245 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13246 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 13247 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 13248 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13249 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13250 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13251 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13252 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13253 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13254 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13255 | |
| 13256 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13257 | ASSERT_TRUE(response); |
| 13258 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 13259 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13260 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13261 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 13262 | |
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!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 13265 | } |
| 13266 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13267 | // GenerateAuthToken is a mighty big test. |
| 13268 | // It tests all permutation of GenerateAuthToken behavior: |
| 13269 | // - Synchronous and Asynchronous completion. |
| 13270 | // - OK or error on completion. |
| 13271 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 13272 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 13273 | // - Non-authenticating and authenticating backend. |
| 13274 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 13275 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13276 | // problems generating an auth token for an authenticating proxy, we don't |
| 13277 | // need to test all permutations of the backend server). |
| 13278 | // |
| 13279 | // The test proceeds by going over each of the configuration cases, and |
| 13280 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 13281 | // specifies both the configuration for the test as well as the expectations |
| 13282 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13283 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13284 | static const char kServer[] = "http://www.example.com"; |
| 13285 | static const char kSecureServer[] = "https://www.example.com"; |
| 13286 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13287 | |
| 13288 | enum AuthTiming { |
| 13289 | AUTH_NONE, |
| 13290 | AUTH_SYNC, |
| 13291 | AUTH_ASYNC, |
| 13292 | }; |
| 13293 | |
| 13294 | const MockWrite kGet( |
| 13295 | "GET / HTTP/1.1\r\n" |
| 13296 | "Host: www.example.com\r\n" |
| 13297 | "Connection: keep-alive\r\n\r\n"); |
| 13298 | const MockWrite kGetProxy( |
| 13299 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13300 | "Host: www.example.com\r\n" |
| 13301 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13302 | const MockWrite kGetAuth( |
| 13303 | "GET / HTTP/1.1\r\n" |
| 13304 | "Host: www.example.com\r\n" |
| 13305 | "Connection: keep-alive\r\n" |
| 13306 | "Authorization: auth_token\r\n\r\n"); |
| 13307 | const MockWrite kGetProxyAuth( |
| 13308 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13309 | "Host: www.example.com\r\n" |
| 13310 | "Proxy-Connection: keep-alive\r\n" |
| 13311 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13312 | const MockWrite kGetAuthThroughProxy( |
| 13313 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13314 | "Host: www.example.com\r\n" |
| 13315 | "Proxy-Connection: keep-alive\r\n" |
| 13316 | "Authorization: auth_token\r\n\r\n"); |
| 13317 | const MockWrite kGetAuthWithProxyAuth( |
| 13318 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 13319 | "Host: www.example.com\r\n" |
| 13320 | "Proxy-Connection: keep-alive\r\n" |
| 13321 | "Proxy-Authorization: auth_token\r\n" |
| 13322 | "Authorization: auth_token\r\n\r\n"); |
| 13323 | const MockWrite kConnect( |
| 13324 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13325 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13326 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 13327 | const MockWrite kConnectProxyAuth( |
| 13328 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13329 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13330 | "Proxy-Connection: keep-alive\r\n" |
| 13331 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 13332 | |
| 13333 | const MockRead kSuccess( |
| 13334 | "HTTP/1.1 200 OK\r\n" |
| 13335 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13336 | "Content-Length: 3\r\n\r\n" |
| 13337 | "Yes"); |
| 13338 | const MockRead kFailure( |
| 13339 | "Should not be called."); |
| 13340 | const MockRead kServerChallenge( |
| 13341 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13342 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13343 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13344 | "Content-Length: 14\r\n\r\n" |
| 13345 | "Unauthorized\r\n"); |
| 13346 | const MockRead kProxyChallenge( |
| 13347 | "HTTP/1.1 407 Unauthorized\r\n" |
| 13348 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 13349 | "Proxy-Connection: close\r\n" |
| 13350 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13351 | "Content-Length: 14\r\n\r\n" |
| 13352 | "Unauthorized\r\n"); |
| 13353 | const MockRead kProxyConnected( |
| 13354 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 13355 | |
| 13356 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 13357 | // no constructors, but the C++ compiler on Windows warns about |
| 13358 | // unspecified data in compound literals. So, moved to using constructors, |
| 13359 | // and TestRound's created with the default constructor should not be used. |
| 13360 | struct TestRound { |
| 13361 | TestRound() |
| 13362 | : expected_rv(ERR_UNEXPECTED), |
| 13363 | extra_write(NULL), |
| 13364 | extra_read(NULL) { |
| 13365 | } |
| 13366 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 13367 | int expected_rv_arg) |
| 13368 | : write(write_arg), |
| 13369 | read(read_arg), |
| 13370 | expected_rv(expected_rv_arg), |
| 13371 | extra_write(NULL), |
| 13372 | extra_read(NULL) { |
| 13373 | } |
| 13374 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 13375 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 13376 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13377 | : write(write_arg), |
| 13378 | read(read_arg), |
| 13379 | expected_rv(expected_rv_arg), |
| 13380 | extra_write(extra_write_arg), |
| 13381 | extra_read(extra_read_arg) { |
| 13382 | } |
| 13383 | MockWrite write; |
| 13384 | MockRead read; |
| 13385 | int expected_rv; |
| 13386 | const MockWrite* extra_write; |
| 13387 | const MockRead* extra_read; |
| 13388 | }; |
| 13389 | |
| 13390 | static const int kNoSSL = 500; |
| 13391 | |
| 13392 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13393 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13394 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13395 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13396 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13397 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13398 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13399 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13400 | int num_auth_rounds; |
| 13401 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13402 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13403 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13404 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13405 | {__LINE__, |
| 13406 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13407 | AUTH_NONE, |
| 13408 | OK, |
| 13409 | kServer, |
| 13410 | AUTH_NONE, |
| 13411 | OK, |
| 13412 | 1, |
| 13413 | kNoSSL, |
| 13414 | {TestRound(kGet, kSuccess, OK)}}, |
| 13415 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13416 | {__LINE__, |
| 13417 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13418 | AUTH_NONE, |
| 13419 | OK, |
| 13420 | kServer, |
| 13421 | AUTH_SYNC, |
| 13422 | OK, |
| 13423 | 2, |
| 13424 | kNoSSL, |
| 13425 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13426 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13427 | {__LINE__, |
| 13428 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13429 | AUTH_NONE, |
| 13430 | OK, |
| 13431 | kServer, |
| 13432 | AUTH_SYNC, |
| 13433 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13434 | 3, |
| 13435 | kNoSSL, |
| 13436 | {TestRound(kGet, kServerChallenge, OK), |
| 13437 | TestRound(kGet, kServerChallenge, OK), |
| 13438 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13439 | {__LINE__, |
| 13440 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13441 | AUTH_NONE, |
| 13442 | OK, |
| 13443 | kServer, |
| 13444 | AUTH_SYNC, |
| 13445 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13446 | 2, |
| 13447 | kNoSSL, |
| 13448 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13449 | {__LINE__, |
| 13450 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13451 | AUTH_NONE, |
| 13452 | OK, |
| 13453 | kServer, |
| 13454 | AUTH_SYNC, |
| 13455 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 13456 | 2, |
| 13457 | kNoSSL, |
| 13458 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13459 | {__LINE__, |
| 13460 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13461 | AUTH_SYNC, |
| 13462 | ERR_FAILED, |
| 13463 | kServer, |
| 13464 | AUTH_NONE, |
| 13465 | OK, |
| 13466 | 2, |
| 13467 | kNoSSL, |
| 13468 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13469 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13470 | {__LINE__, |
| 13471 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13472 | AUTH_ASYNC, |
| 13473 | ERR_FAILED, |
| 13474 | kServer, |
| 13475 | AUTH_NONE, |
| 13476 | OK, |
| 13477 | 2, |
| 13478 | kNoSSL, |
| 13479 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13480 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13481 | {__LINE__, |
| 13482 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13483 | AUTH_NONE, |
| 13484 | OK, |
| 13485 | kServer, |
| 13486 | AUTH_SYNC, |
| 13487 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13488 | 2, |
| 13489 | kNoSSL, |
| 13490 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13491 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13492 | {__LINE__, |
| 13493 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13494 | AUTH_NONE, |
| 13495 | OK, |
| 13496 | kServer, |
| 13497 | AUTH_ASYNC, |
| 13498 | ERR_FAILED, |
| 13499 | 2, |
| 13500 | kNoSSL, |
| 13501 | {TestRound(kGet, kServerChallenge, OK), |
| 13502 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13503 | {__LINE__, |
| 13504 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13505 | AUTH_NONE, |
| 13506 | OK, |
| 13507 | kServer, |
| 13508 | AUTH_ASYNC, |
| 13509 | OK, |
| 13510 | 2, |
| 13511 | kNoSSL, |
| 13512 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13513 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13514 | {__LINE__, |
| 13515 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13516 | AUTH_NONE, |
| 13517 | OK, |
| 13518 | kServer, |
| 13519 | AUTH_ASYNC, |
| 13520 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13521 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13522 | kNoSSL, |
| 13523 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13524 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 13525 | TestRound(kGet, kServerChallenge, OK), |
| 13526 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13527 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13528 | {__LINE__, |
| 13529 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13530 | AUTH_NONE, |
| 13531 | OK, |
| 13532 | kServer, |
| 13533 | AUTH_NONE, |
| 13534 | OK, |
| 13535 | 1, |
| 13536 | kNoSSL, |
| 13537 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 13538 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13539 | {__LINE__, |
| 13540 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13541 | AUTH_NONE, |
| 13542 | OK, |
| 13543 | kServer, |
| 13544 | AUTH_SYNC, |
| 13545 | OK, |
| 13546 | 2, |
| 13547 | kNoSSL, |
| 13548 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13549 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13550 | {__LINE__, |
| 13551 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13552 | AUTH_NONE, |
| 13553 | OK, |
| 13554 | kServer, |
| 13555 | AUTH_SYNC, |
| 13556 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13557 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13558 | kNoSSL, |
| 13559 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13560 | TestRound(kGetProxy, kServerChallenge, OK), |
| 13561 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13562 | {__LINE__, |
| 13563 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13564 | AUTH_NONE, |
| 13565 | OK, |
| 13566 | kServer, |
| 13567 | AUTH_ASYNC, |
| 13568 | OK, |
| 13569 | 2, |
| 13570 | kNoSSL, |
| 13571 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13572 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13573 | {__LINE__, |
| 13574 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13575 | AUTH_NONE, |
| 13576 | OK, |
| 13577 | kServer, |
| 13578 | AUTH_ASYNC, |
| 13579 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13580 | 2, |
| 13581 | kNoSSL, |
| 13582 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13583 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13584 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13585 | {__LINE__, |
| 13586 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13587 | AUTH_SYNC, |
| 13588 | OK, |
| 13589 | kServer, |
| 13590 | AUTH_NONE, |
| 13591 | OK, |
| 13592 | 2, |
| 13593 | kNoSSL, |
| 13594 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13595 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13596 | {__LINE__, |
| 13597 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13598 | AUTH_SYNC, |
| 13599 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13600 | kServer, |
| 13601 | AUTH_NONE, |
| 13602 | OK, |
| 13603 | 2, |
| 13604 | kNoSSL, |
| 13605 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13606 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13607 | {__LINE__, |
| 13608 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13609 | AUTH_ASYNC, |
| 13610 | OK, |
| 13611 | kServer, |
| 13612 | AUTH_NONE, |
| 13613 | OK, |
| 13614 | 2, |
| 13615 | kNoSSL, |
| 13616 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13617 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13618 | {__LINE__, |
| 13619 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13620 | AUTH_ASYNC, |
| 13621 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13622 | kServer, |
| 13623 | AUTH_NONE, |
| 13624 | OK, |
| 13625 | 2, |
| 13626 | kNoSSL, |
| 13627 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13628 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13629 | {__LINE__, |
| 13630 | kProxy, |
| 13631 | AUTH_ASYNC, |
| 13632 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13633 | kServer, |
| 13634 | AUTH_NONE, |
| 13635 | OK, |
| 13636 | 3, |
| 13637 | kNoSSL, |
| 13638 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13639 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13640 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13641 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13642 | {__LINE__, |
| 13643 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13644 | AUTH_SYNC, |
| 13645 | OK, |
| 13646 | kServer, |
| 13647 | AUTH_SYNC, |
| 13648 | OK, |
| 13649 | 3, |
| 13650 | kNoSSL, |
| 13651 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13652 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13653 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13654 | {__LINE__, |
| 13655 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13656 | AUTH_SYNC, |
| 13657 | OK, |
| 13658 | kServer, |
| 13659 | AUTH_SYNC, |
| 13660 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13661 | 3, |
| 13662 | kNoSSL, |
| 13663 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13664 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13665 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13666 | {__LINE__, |
| 13667 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13668 | AUTH_ASYNC, |
| 13669 | OK, |
| 13670 | kServer, |
| 13671 | AUTH_SYNC, |
| 13672 | OK, |
| 13673 | 3, |
| 13674 | kNoSSL, |
| 13675 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13676 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13677 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13678 | {__LINE__, |
| 13679 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13680 | AUTH_ASYNC, |
| 13681 | OK, |
| 13682 | kServer, |
| 13683 | AUTH_SYNC, |
| 13684 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13685 | 3, |
| 13686 | kNoSSL, |
| 13687 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13688 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13689 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13690 | {__LINE__, |
| 13691 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13692 | AUTH_SYNC, |
| 13693 | OK, |
| 13694 | kServer, |
| 13695 | AUTH_ASYNC, |
| 13696 | OK, |
| 13697 | 3, |
| 13698 | kNoSSL, |
| 13699 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13700 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13701 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13702 | {__LINE__, |
| 13703 | kProxy, |
| 13704 | AUTH_SYNC, |
| 13705 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13706 | kServer, |
| 13707 | AUTH_ASYNC, |
| 13708 | OK, |
| 13709 | 4, |
| 13710 | kNoSSL, |
| 13711 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13712 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13713 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13714 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 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 | ERR_INVALID_AUTH_CREDENTIALS, |
| 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), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13726 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13727 | {__LINE__, |
| 13728 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13729 | AUTH_ASYNC, |
| 13730 | OK, |
| 13731 | kServer, |
| 13732 | AUTH_ASYNC, |
| 13733 | OK, |
| 13734 | 3, |
| 13735 | kNoSSL, |
| 13736 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13737 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13738 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13739 | {__LINE__, |
| 13740 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13741 | AUTH_ASYNC, |
| 13742 | OK, |
| 13743 | kServer, |
| 13744 | AUTH_ASYNC, |
| 13745 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13746 | 3, |
| 13747 | kNoSSL, |
| 13748 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13749 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13750 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13751 | {__LINE__, |
| 13752 | kProxy, |
| 13753 | AUTH_ASYNC, |
| 13754 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13755 | kServer, |
| 13756 | AUTH_ASYNC, |
| 13757 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13758 | 4, |
| 13759 | kNoSSL, |
| 13760 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 13761 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 13762 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 13763 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13764 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13765 | {__LINE__, |
| 13766 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13767 | AUTH_NONE, |
| 13768 | OK, |
| 13769 | kSecureServer, |
| 13770 | AUTH_NONE, |
| 13771 | OK, |
| 13772 | 1, |
| 13773 | 0, |
| 13774 | {TestRound(kGet, kSuccess, OK)}}, |
| 13775 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13776 | {__LINE__, |
| 13777 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13778 | AUTH_NONE, |
| 13779 | OK, |
| 13780 | kSecureServer, |
| 13781 | AUTH_SYNC, |
| 13782 | OK, |
| 13783 | 2, |
| 13784 | 0, |
| 13785 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13786 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13787 | {__LINE__, |
| 13788 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13789 | AUTH_NONE, |
| 13790 | OK, |
| 13791 | kSecureServer, |
| 13792 | AUTH_SYNC, |
| 13793 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13794 | 2, |
| 13795 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13796 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13797 | {__LINE__, |
| 13798 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13799 | AUTH_NONE, |
| 13800 | OK, |
| 13801 | kSecureServer, |
| 13802 | AUTH_ASYNC, |
| 13803 | OK, |
| 13804 | 2, |
| 13805 | 0, |
| 13806 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13807 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13808 | {__LINE__, |
| 13809 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13810 | AUTH_NONE, |
| 13811 | OK, |
| 13812 | kSecureServer, |
| 13813 | AUTH_ASYNC, |
| 13814 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13815 | 2, |
| 13816 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13817 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13818 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13819 | {__LINE__, |
| 13820 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13821 | AUTH_NONE, |
| 13822 | OK, |
| 13823 | kSecureServer, |
| 13824 | AUTH_NONE, |
| 13825 | OK, |
| 13826 | 1, |
| 13827 | 0, |
| 13828 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 13829 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13830 | {__LINE__, |
| 13831 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13832 | AUTH_NONE, |
| 13833 | OK, |
| 13834 | kSecureServer, |
| 13835 | AUTH_SYNC, |
| 13836 | OK, |
| 13837 | 2, |
| 13838 | 0, |
| 13839 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13840 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13841 | {__LINE__, |
| 13842 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13843 | AUTH_NONE, |
| 13844 | OK, |
| 13845 | kSecureServer, |
| 13846 | AUTH_SYNC, |
| 13847 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13848 | 2, |
| 13849 | 0, |
| 13850 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13851 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13852 | {__LINE__, |
| 13853 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13854 | AUTH_NONE, |
| 13855 | OK, |
| 13856 | kSecureServer, |
| 13857 | AUTH_ASYNC, |
| 13858 | OK, |
| 13859 | 2, |
| 13860 | 0, |
| 13861 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13862 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13863 | {__LINE__, |
| 13864 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13865 | AUTH_NONE, |
| 13866 | OK, |
| 13867 | kSecureServer, |
| 13868 | AUTH_ASYNC, |
| 13869 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13870 | 2, |
| 13871 | 0, |
| 13872 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13873 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13874 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13875 | {__LINE__, |
| 13876 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13877 | AUTH_SYNC, |
| 13878 | OK, |
| 13879 | kSecureServer, |
| 13880 | AUTH_NONE, |
| 13881 | OK, |
| 13882 | 2, |
| 13883 | 1, |
| 13884 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13885 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13886 | {__LINE__, |
| 13887 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13888 | AUTH_SYNC, |
| 13889 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13890 | kSecureServer, |
| 13891 | AUTH_NONE, |
| 13892 | OK, |
| 13893 | 2, |
| 13894 | kNoSSL, |
| 13895 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13896 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13897 | {__LINE__, |
| 13898 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13899 | AUTH_SYNC, |
| 13900 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13901 | kSecureServer, |
| 13902 | AUTH_NONE, |
| 13903 | OK, |
| 13904 | 2, |
| 13905 | kNoSSL, |
| 13906 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13907 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13908 | {__LINE__, |
| 13909 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13910 | AUTH_SYNC, |
| 13911 | ERR_UNEXPECTED, |
| 13912 | kSecureServer, |
| 13913 | AUTH_NONE, |
| 13914 | OK, |
| 13915 | 2, |
| 13916 | kNoSSL, |
| 13917 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13918 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13919 | {__LINE__, |
| 13920 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13921 | AUTH_ASYNC, |
| 13922 | OK, |
| 13923 | kSecureServer, |
| 13924 | AUTH_NONE, |
| 13925 | OK, |
| 13926 | 2, |
| 13927 | 1, |
| 13928 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13929 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13930 | {__LINE__, |
| 13931 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13932 | AUTH_ASYNC, |
| 13933 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13934 | kSecureServer, |
| 13935 | AUTH_NONE, |
| 13936 | OK, |
| 13937 | 2, |
| 13938 | kNoSSL, |
| 13939 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13940 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13941 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13942 | {__LINE__, |
| 13943 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13944 | AUTH_SYNC, |
| 13945 | OK, |
| 13946 | kSecureServer, |
| 13947 | AUTH_SYNC, |
| 13948 | OK, |
| 13949 | 3, |
| 13950 | 1, |
| 13951 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13952 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13953 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13954 | TestRound(kGetAuth, kSuccess, OK)}}, |
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_SYNC, |
| 13958 | OK, |
| 13959 | kSecureServer, |
| 13960 | AUTH_SYNC, |
| 13961 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13962 | 3, |
| 13963 | 1, |
| 13964 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13965 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13966 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13967 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13968 | {__LINE__, |
| 13969 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13970 | AUTH_ASYNC, |
| 13971 | OK, |
| 13972 | kSecureServer, |
| 13973 | AUTH_SYNC, |
| 13974 | OK, |
| 13975 | 3, |
| 13976 | 1, |
| 13977 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13978 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13979 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13980 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13981 | {__LINE__, |
| 13982 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13983 | AUTH_ASYNC, |
| 13984 | OK, |
| 13985 | kSecureServer, |
| 13986 | AUTH_SYNC, |
| 13987 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13988 | 3, |
| 13989 | 1, |
| 13990 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13991 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13992 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13993 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13994 | {__LINE__, |
| 13995 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13996 | AUTH_SYNC, |
| 13997 | OK, |
| 13998 | kSecureServer, |
| 13999 | AUTH_ASYNC, |
| 14000 | OK, |
| 14001 | 3, |
| 14002 | 1, |
| 14003 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14004 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14005 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14006 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14007 | {__LINE__, |
| 14008 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14009 | AUTH_SYNC, |
| 14010 | OK, |
| 14011 | kSecureServer, |
| 14012 | AUTH_ASYNC, |
| 14013 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14014 | 3, |
| 14015 | 1, |
| 14016 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14017 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14018 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14019 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14020 | {__LINE__, |
| 14021 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14022 | AUTH_ASYNC, |
| 14023 | OK, |
| 14024 | kSecureServer, |
| 14025 | AUTH_ASYNC, |
| 14026 | OK, |
| 14027 | 3, |
| 14028 | 1, |
| 14029 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14030 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14031 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14032 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14033 | {__LINE__, |
| 14034 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 14035 | AUTH_ASYNC, |
| 14036 | OK, |
| 14037 | kSecureServer, |
| 14038 | AUTH_ASYNC, |
| 14039 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14040 | 3, |
| 14041 | 1, |
| 14042 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14043 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14044 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14045 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14046 | {__LINE__, |
| 14047 | kProxy, |
| 14048 | AUTH_ASYNC, |
| 14049 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14050 | kSecureServer, |
| 14051 | AUTH_ASYNC, |
| 14052 | ERR_INVALID_AUTH_CREDENTIALS, |
| 14053 | 4, |
| 14054 | 2, |
| 14055 | {TestRound(kConnect, kProxyChallenge, OK), |
| 14056 | TestRound(kConnect, kProxyChallenge, OK), |
| 14057 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 14058 | &kServerChallenge), |
| 14059 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14060 | }; |
| 14061 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14062 | for (const auto& test_config : test_configs) { |
| 14063 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 14064 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14065 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14066 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14067 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14068 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14069 | |
| 14070 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14071 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14072 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14073 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14074 | std::string auth_challenge = "Mock realm=proxy"; |
| 14075 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14076 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14077 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14078 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14079 | empty_ssl_info, origin, |
| 14080 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14081 | auth_handler->SetGenerateExpectation( |
| 14082 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14083 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14084 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 14085 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14086 | } |
| 14087 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 14088 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14089 | std::string auth_challenge = "Mock realm=server"; |
| 14090 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14091 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14092 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14093 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14094 | empty_ssl_info, origin, |
| 14095 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14096 | auth_handler->SetGenerateExpectation( |
| 14097 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14098 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14099 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14100 | |
| 14101 | // The second handler always succeeds. It should only be used where there |
| 14102 | // are multiple auth sessions for server auth in the same network |
| 14103 | // transaction using the same auth scheme. |
| 14104 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14105 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14106 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 14107 | empty_ssl_info, origin, |
| 14108 | NetLogWithSource()); |
| 14109 | second_handler->SetGenerateExpectation(true, OK); |
| 14110 | auth_factory->AddMockHandler(second_handler.release(), |
| 14111 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14112 | } |
| 14113 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14114 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14115 | ProxyResolutionService::CreateFixed(test_config.proxy_url, |
| 14116 | TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14117 | } else { |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14118 | session_deps_.proxy_resolution_service = |
| 14119 | ProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14120 | } |
| 14121 | |
| 14122 | HttpRequestInfo request; |
| 14123 | request.method = "GET"; |
| 14124 | request.url = GURL(test_config.server_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14125 | request.traffic_annotation = |
| 14126 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14127 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14128 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14129 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14130 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 14131 | |
| 14132 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 14133 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14134 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14135 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14136 | const TestRound& read_write_round = test_config.rounds[round]; |
| 14137 | |
| 14138 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14139 | mock_reads.back().push_back(read_write_round.read); |
| 14140 | mock_writes.back().push_back(read_write_round.write); |
| 14141 | |
| 14142 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 14143 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 14144 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14145 | mock_reads.push_back(std::vector<MockRead>()); |
| 14146 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14147 | } |
| 14148 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14149 | if (read_write_round.extra_read) { |
| 14150 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14151 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14152 | if (read_write_round.extra_write) { |
| 14153 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 14154 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14155 | |
| 14156 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14157 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14158 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14159 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14160 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14161 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14162 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14163 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14164 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14165 | mock_reads[i], mock_writes[i])); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14166 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 14167 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14168 | } |
| 14169 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 14170 | // Transaction must be created after DataProviders, so it's destroyed before |
| 14171 | // they are as well. |
| 14172 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 14173 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14174 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 14175 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 14176 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14177 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14178 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14179 | int rv; |
| 14180 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14181 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14182 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14183 | rv = trans.RestartWithAuth( |
| 14184 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14185 | } |
| 14186 | if (rv == ERR_IO_PENDING) |
| 14187 | rv = callback.WaitForResult(); |
| 14188 | |
| 14189 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14190 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14191 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 14192 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14193 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 14194 | continue; |
| 14195 | } |
| 14196 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14197 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14198 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14199 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 14200 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 14201 | } |
| 14202 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 14203 | } |
| 14204 | } |
| 14205 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14206 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14207 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14208 | HttpAuthHandlerMock::Factory* auth_factory( |
| 14209 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14210 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 14211 | session_deps_.proxy_resolution_service = |
| 14212 | ProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14213 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14214 | |
| 14215 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 14216 | auth_handler->set_connection_based(true); |
| 14217 | std::string auth_challenge = "Mock realm=server"; |
| 14218 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 14219 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 14220 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 14221 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14222 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14223 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 14224 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14225 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14226 | int rv = OK; |
| 14227 | const HttpResponseInfo* response = NULL; |
| 14228 | HttpRequestInfo request; |
| 14229 | request.method = "GET"; |
| 14230 | request.url = origin; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14231 | request.traffic_annotation = |
| 14232 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14233 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14234 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14235 | |
| 14236 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 14237 | // to validate that the TCP socket is not released to the pool between |
| 14238 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 14239 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14240 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14241 | 50, // Max sockets for pool |
| 14242 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 14243 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 14244 | NULL, session_deps_.net_log); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14245 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 14246 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 14247 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14248 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14249 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14250 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14251 | |
| 14252 | const MockWrite kGet( |
| 14253 | "GET / HTTP/1.1\r\n" |
| 14254 | "Host: www.example.com\r\n" |
| 14255 | "Connection: keep-alive\r\n\r\n"); |
| 14256 | const MockWrite kGetAuth( |
| 14257 | "GET / HTTP/1.1\r\n" |
| 14258 | "Host: www.example.com\r\n" |
| 14259 | "Connection: keep-alive\r\n" |
| 14260 | "Authorization: auth_token\r\n\r\n"); |
| 14261 | |
| 14262 | const MockRead kServerChallenge( |
| 14263 | "HTTP/1.1 401 Unauthorized\r\n" |
| 14264 | "WWW-Authenticate: Mock realm=server\r\n" |
| 14265 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14266 | "Content-Length: 14\r\n\r\n" |
| 14267 | "Unauthorized\r\n"); |
| 14268 | const MockRead kSuccess( |
| 14269 | "HTTP/1.1 200 OK\r\n" |
| 14270 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 14271 | "Content-Length: 3\r\n\r\n" |
| 14272 | "Yes"); |
| 14273 | |
| 14274 | MockWrite writes[] = { |
| 14275 | // First round |
| 14276 | kGet, |
| 14277 | // Second round |
| 14278 | kGetAuth, |
| 14279 | // Third round |
| 14280 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14281 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14282 | kGetAuth, |
| 14283 | // Competing request |
| 14284 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14285 | }; |
| 14286 | MockRead reads[] = { |
| 14287 | // First round |
| 14288 | kServerChallenge, |
| 14289 | // Second round |
| 14290 | kServerChallenge, |
| 14291 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14292 | kServerChallenge, |
| 14293 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14294 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14295 | // Competing response |
| 14296 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14297 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14298 | StaticSocketDataProvider data_provider(reads, writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14299 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14300 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 14301 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14302 | |
| 14303 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14304 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14305 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14306 | if (rv == ERR_IO_PENDING) |
| 14307 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14308 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14309 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14310 | ASSERT_TRUE(response); |
| 14311 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14312 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14313 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14314 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14315 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14316 | // In between rounds, another request comes in for the same domain. |
| 14317 | // It should not be able to grab the TCP socket that trans has already |
| 14318 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14319 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14320 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14321 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 14322 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14323 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14324 | // callback_compete.WaitForResult at this point would stall forever, |
| 14325 | // since the HttpNetworkTransaction does not release the request back to |
| 14326 | // the pool until after authentication completes. |
| 14327 | |
| 14328 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14329 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14330 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14331 | if (rv == ERR_IO_PENDING) |
| 14332 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14333 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14334 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14335 | ASSERT_TRUE(response); |
| 14336 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14337 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14338 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14339 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14340 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14341 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14342 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14343 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14344 | if (rv == ERR_IO_PENDING) |
| 14345 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14346 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14347 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14348 | ASSERT_TRUE(response); |
| 14349 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14350 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14351 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 14352 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14353 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14354 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14355 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14356 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 14357 | if (rv == ERR_IO_PENDING) |
| 14358 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14359 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14360 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14361 | ASSERT_TRUE(response); |
| 14362 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14363 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14364 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 14365 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 14366 | // auth handler should transition to a DONE state in concert with the remote |
| 14367 | // server. But that's not something we can test here with a mock handler. |
| 14368 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 14369 | auth_handler->state()); |
| 14370 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14371 | // Read the body since the fourth round was successful. This will also |
| 14372 | // release the socket back to the pool. |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 14373 | scoped_refptr<IOBufferWithSize> io_buf = |
| 14374 | base::MakeRefCounted<IOBufferWithSize>(50); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14375 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14376 | if (rv == ERR_IO_PENDING) |
| 14377 | rv = callback.WaitForResult(); |
| 14378 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14379 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14380 | EXPECT_EQ(0, rv); |
| 14381 | // There are still 0 idle sockets, since the trans_compete transaction |
| 14382 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14383 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14384 | |
| 14385 | // The competing request can now finish. Wait for the headers and then |
| 14386 | // read the body. |
| 14387 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14388 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14389 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14390 | if (rv == ERR_IO_PENDING) |
| 14391 | rv = callback.WaitForResult(); |
| 14392 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14393 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 14394 | EXPECT_EQ(0, rv); |
| 14395 | |
| 14396 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 14397 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 14398 | } |
| 14399 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14400 | // This tests the case that a request is issued via http instead of spdy after |
| 14401 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14402 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14403 | HttpRequestInfo request; |
| 14404 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14405 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14406 | request.traffic_annotation = |
| 14407 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14408 | |
| 14409 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14410 | MockWrite( |
| 14411 | "GET / HTTP/1.1\r\n" |
| 14412 | "Host: www.example.org\r\n" |
| 14413 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14414 | }; |
| 14415 | |
| 14416 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14417 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 14418 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 14419 | MockRead("\r\n"), |
| 14420 | MockRead("hello world"), |
| 14421 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14422 | }; |
| 14423 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14424 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14425 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14426 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14427 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14428 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14429 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14430 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14431 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14432 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14433 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14434 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14435 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14436 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14437 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14438 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14439 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14440 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14441 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14442 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14443 | ASSERT_TRUE(response); |
| 14444 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14445 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14446 | |
| 14447 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14448 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14449 | EXPECT_EQ("hello world", response_data); |
| 14450 | |
| 14451 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14452 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 14453 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14454 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 14455 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 14456 | // immediate server closing of the socket. |
| 14457 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14458 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14459 | HttpRequestInfo request; |
| 14460 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14461 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14462 | request.traffic_annotation = |
| 14463 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14464 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14465 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14466 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14467 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14468 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14469 | spdy::SpdySerializedFrame req( |
| 14470 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14471 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14472 | |
| 14473 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14474 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14475 | }; |
| 14476 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14477 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14478 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14479 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14480 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14481 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14482 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14483 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14484 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14485 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14486 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14487 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 14488 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 14489 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14490 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 14491 | // it gets it. This is needed since the auth handler may get destroyed |
| 14492 | // before we get a chance to query it. |
| 14493 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 14494 | public: |
| 14495 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 14496 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 14497 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14498 | |
| 14499 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14500 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 14501 | const HttpRequestInfo* request, |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14502 | CompletionOnceCallback callback, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14503 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14504 | *url_ = request->url; |
| 14505 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 14506 | credentials, request, std::move(callback), auth_token); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14507 | } |
| 14508 | |
| 14509 | private: |
| 14510 | GURL* url_; |
| 14511 | }; |
| 14512 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14513 | // Test that if we cancel the transaction as the connection is completing, that |
| 14514 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14515 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14516 | // Setup everything about the connection to complete synchronously, so that |
| 14517 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 14518 | // for is the callback from the HttpStreamRequest. |
| 14519 | // Then cancel the transaction. |
| 14520 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 14521 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14522 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14523 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 14524 | MockRead(SYNCHRONOUS, "hello world"), |
| 14525 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14526 | }; |
| 14527 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14528 | HttpRequestInfo request; |
| 14529 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14530 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14531 | request.traffic_annotation = |
| 14532 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14533 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14534 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 14535 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14536 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14537 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14538 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14539 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14540 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14541 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14542 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14543 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14544 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14545 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14546 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 14547 | trans.reset(); // Cancel the transaction here. |
| 14548 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14549 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 14550 | } |
| 14551 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14552 | // Test that if a transaction is cancelled after receiving the headers, the |
| 14553 | // stream is drained properly and added back to the socket pool. The main |
| 14554 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 14555 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 14556 | // deleted. |
| 14557 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14558 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14559 | MockRead data_reads[] = { |
| 14560 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 14561 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 14562 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 14563 | MockRead(ASYNC, "1"), |
| 14564 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 14565 | // HttpNetworkTransaction has been deleted. |
| 14566 | MockRead(ASYNC, "2"), |
| 14567 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 14568 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14569 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14570 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14571 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14572 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14573 | |
| 14574 | { |
| 14575 | HttpRequestInfo request; |
| 14576 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14577 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14578 | request.traffic_annotation = |
| 14579 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14580 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14581 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14582 | TestCompletionCallback callback; |
| 14583 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14584 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14585 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14586 | callback.WaitForResult(); |
| 14587 | |
| 14588 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14589 | ASSERT_TRUE(response); |
| 14590 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14591 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 14592 | |
| 14593 | // The transaction and HttpRequestInfo are deleted. |
| 14594 | } |
| 14595 | |
| 14596 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 14597 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14598 | |
| 14599 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 14600 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 14601 | } |
| 14602 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14603 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14604 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14605 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14606 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14607 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14608 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14609 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14610 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14611 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14612 | HttpRequestInfo request; |
| 14613 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14614 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14615 | request.traffic_annotation = |
| 14616 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14617 | |
| 14618 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14619 | MockWrite( |
| 14620 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 14621 | "Host: www.example.org\r\n" |
| 14622 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14623 | }; |
| 14624 | |
| 14625 | MockRead data_reads1[] = { |
| 14626 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14627 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14628 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14629 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14630 | }; |
| 14631 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14632 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14633 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14634 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14635 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14636 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14637 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14638 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14639 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14640 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14641 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14642 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14643 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14644 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14645 | |
| 14646 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14647 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14648 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14649 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14650 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14651 | |
| 14652 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14653 | EXPECT_EQ(200, response->headers->response_code()); |
| 14654 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14655 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14656 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14657 | HostPortPair::FromString("myproxy:70")), |
| 14658 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14659 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14660 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14661 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14662 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14663 | |
| 14664 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14665 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14666 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14667 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14668 | } |
| 14669 | |
| 14670 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14671 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14672 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14673 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14674 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14675 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14676 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14677 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14678 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14679 | HttpRequestInfo request; |
| 14680 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14681 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14682 | request.traffic_annotation = |
| 14683 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14684 | |
| 14685 | // Since we have proxy, should try to establish tunnel. |
| 14686 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14687 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14688 | "Host: www.example.org:443\r\n" |
| 14689 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14690 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14691 | MockWrite("GET / HTTP/1.1\r\n" |
| 14692 | "Host: www.example.org\r\n" |
| 14693 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14694 | }; |
| 14695 | |
| 14696 | MockRead data_reads1[] = { |
| 14697 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14698 | |
| 14699 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14700 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14701 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14702 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14703 | }; |
| 14704 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14705 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14706 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14707 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14708 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14709 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14710 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14711 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14712 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14713 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14714 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14715 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 14716 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14717 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14718 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14719 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14720 | |
| 14721 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14722 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14723 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14724 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14725 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14726 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14727 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14728 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14729 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14730 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14731 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14732 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14733 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14734 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14735 | |
| 14736 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14737 | EXPECT_EQ(200, response->headers->response_code()); |
| 14738 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14739 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14740 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14741 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14742 | HostPortPair::FromString("myproxy:70")), |
| 14743 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 14744 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 14745 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 14746 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14747 | |
| 14748 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14749 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 14750 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14751 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14752 | } |
| 14753 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14754 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 14755 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14756 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 14757 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14758 | ProxyResolutionService::CreateFixedFromPacResult( |
| 14759 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14760 | BoundTestNetLog log; |
| 14761 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14762 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14763 | |
| 14764 | HttpRequestInfo request; |
| 14765 | request.method = "GET"; |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14766 | request.url = GURL("https://[::2]:443/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14767 | request.traffic_annotation = |
| 14768 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14769 | |
| 14770 | // Since we have proxy, should try to establish tunnel. |
| 14771 | MockWrite data_writes1[] = { |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14772 | MockWrite("CONNECT [::2]:443 HTTP/1.1\r\n" |
| 14773 | "Host: [::2]:443\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14774 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 14775 | |
| 14776 | MockWrite("GET / HTTP/1.1\r\n" |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 14777 | "Host: [::2]\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14778 | "Connection: keep-alive\r\n\r\n"), |
| 14779 | }; |
| 14780 | |
| 14781 | MockRead data_reads1[] = { |
| 14782 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14783 | |
| 14784 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14785 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14786 | MockRead("Content-Length: 100\r\n\r\n"), |
| 14787 | MockRead(SYNCHRONOUS, OK), |
| 14788 | }; |
| 14789 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14790 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14791 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14792 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14793 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14794 | |
| 14795 | TestCompletionCallback callback1; |
| 14796 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14797 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14798 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14799 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14800 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14801 | |
| 14802 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14803 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14804 | TestNetLogEntry::List entries; |
| 14805 | log.GetEntries(&entries); |
| 14806 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14807 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14808 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14809 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14810 | entries, pos, |
| 14811 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14812 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14813 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14814 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14815 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14816 | |
| 14817 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14818 | EXPECT_EQ(200, response->headers->response_code()); |
| 14819 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14820 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14821 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14822 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14823 | HostPortPair::FromString("myproxy:70")), |
| 14824 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14825 | |
| 14826 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14827 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14828 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14829 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14830 | } |
| 14831 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14832 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 14833 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14834 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14835 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 14836 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14837 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14838 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14839 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14840 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14841 | HttpRequestInfo request; |
| 14842 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14843 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14844 | request.traffic_annotation = |
| 14845 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14846 | |
| 14847 | // Since we have proxy, should try to establish tunnel. |
| 14848 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14849 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14850 | "Host: www.example.org:443\r\n" |
| 14851 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14852 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14853 | MockWrite("GET / HTTP/1.1\r\n" |
| 14854 | "Host: www.example.org\r\n" |
| 14855 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14856 | }; |
| 14857 | |
| 14858 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14859 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14860 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14861 | }; |
| 14862 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14863 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14864 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14865 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14866 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14867 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14868 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14869 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14870 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14871 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14872 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14873 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14874 | |
| 14875 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14876 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14877 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14878 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14879 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14880 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14881 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14882 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14883 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14884 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14885 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14886 | } |
| 14887 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14888 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14889 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14890 | spdy::SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14891 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14892 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14893 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14894 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 14895 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14896 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14897 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14898 | }; |
| 14899 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14900 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14901 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14902 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14903 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14904 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14905 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14906 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14907 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14908 | |
| 14909 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14910 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14911 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 14912 | PRIVACY_MODE_DISABLED, |
| 14913 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14914 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 14915 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14916 | |
| 14917 | HttpRequestInfo request; |
| 14918 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14919 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14920 | request.traffic_annotation = |
| 14921 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14922 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14923 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14924 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14925 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14926 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14927 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14928 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14929 | } |
| 14930 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14931 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14932 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14933 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14934 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14935 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14936 | request_info.url = GURL("https://www.example.com/"); |
| 14937 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14938 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14939 | request_info.traffic_annotation = |
| 14940 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14941 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14942 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14943 | MockWrite data_writes[] = { |
| 14944 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14945 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14946 | StaticSocketDataProvider data(base::span<MockRead>(), data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14947 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14948 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14949 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14950 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14951 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14952 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14953 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14954 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14955 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14956 | rv = callback.WaitForResult(); |
| 14957 | ASSERT_EQ(error, rv); |
| 14958 | } |
| 14959 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14960 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14961 | // Just check a grab bag of cert errors. |
| 14962 | static const int kErrors[] = { |
| 14963 | ERR_CERT_COMMON_NAME_INVALID, |
| 14964 | ERR_CERT_AUTHORITY_INVALID, |
| 14965 | ERR_CERT_DATE_INVALID, |
| 14966 | }; |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 14967 | for (size_t i = 0; i < base::size(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14968 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 14969 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14970 | } |
| 14971 | } |
| 14972 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14973 | // Ensure that a client certificate is removed from the SSL client auth |
| 14974 | // cache when: |
| 14975 | // 1) No proxy is involved. |
| 14976 | // 2) TLS False Start is disabled. |
| 14977 | // 3) The initial TLS handshake requests a client certificate. |
| 14978 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14979 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14980 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14981 | request_info.url = GURL("https://www.example.com/"); |
| 14982 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14983 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14984 | request_info.traffic_annotation = |
| 14985 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14986 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14987 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14988 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14989 | |
| 14990 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 14991 | // CertificateRequest is received for the first time, the handshake will |
| 14992 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14993 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14994 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14995 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14996 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14997 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14998 | |
| 14999 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 15000 | // False Start is not being used, the result of the SSL handshake will be |
| 15001 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 15002 | // matches the result of a server sending a handshake_failure alert, |
| 15003 | // rather than a Finished message, because it requires a client |
| 15004 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15005 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15006 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15007 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15008 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15009 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15010 | |
| 15011 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 15012 | // connection to a server fails during an SSL handshake, |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15013 | // HttpNetworkTransaction will attempt to fallback to TLSv1.2 if the previous |
| 15014 | // connection was attempted with TLSv1.3. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15015 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15016 | // requiring a client certificate, this fallback handshake should also |
| 15017 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15018 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
Steven Valdez | 0ef94d0 | 2018-11-19 23:28:13 | [diff] [blame] | 15019 | ssl_data3.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_2; |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15020 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15021 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15022 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15023 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15024 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15025 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 15026 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 15027 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 15028 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15029 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 15030 | // requiring a client certificate, this fallback handshake should also |
| 15031 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15032 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15033 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15034 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15035 | StaticSocketDataProvider data4; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15036 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15037 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15038 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15039 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15040 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15041 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15042 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15043 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15044 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15045 | |
| 15046 | // Complete the SSL handshake, which should abort due to requiring a |
| 15047 | // client certificate. |
| 15048 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15049 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15050 | |
| 15051 | // Indicate that no certificate should be supplied. From the perspective |
| 15052 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15053 | // certificate, so this is the same as supply a |
| 15054 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15055 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15056 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15057 | |
| 15058 | // Ensure the certificate was added to the client auth cache before |
| 15059 | // allowing the connection to continue restarting. |
| 15060 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15061 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15062 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15063 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15064 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15065 | |
| 15066 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15067 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15068 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15069 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15070 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15071 | |
| 15072 | // Ensure that the client certificate is removed from the cache on a |
| 15073 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15074 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15075 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15076 | } |
| 15077 | |
| 15078 | // Ensure that a client certificate is removed from the SSL client auth |
| 15079 | // cache when: |
| 15080 | // 1) No proxy is involved. |
| 15081 | // 2) TLS False Start is enabled. |
| 15082 | // 3) The initial TLS handshake requests a client certificate. |
| 15083 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15084 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15085 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15086 | request_info.url = GURL("https://www.example.com/"); |
| 15087 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15088 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15089 | request_info.traffic_annotation = |
| 15090 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 15091 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15092 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15093 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15094 | |
| 15095 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 15096 | // return successfully after reading up to the peer's Certificate message. |
| 15097 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 15098 | // enqueue application data to be sent in the same packet as the |
| 15099 | // ChangeCipherSpec and Finished messages. |
| 15100 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 15101 | // called, which expects to process the peer's ChangeCipherSpec and |
| 15102 | // Finished messages. If there was an error negotiating with the peer, |
| 15103 | // such as due to the peer requiring a client certificate when none was |
| 15104 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 15105 | // called. |
| 15106 | |
| 15107 | // Like the non-False Start case, when a client certificate is requested by |
| 15108 | // the peer, the handshake is aborted during the Connect() call. |
| 15109 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15110 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15111 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15112 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15113 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15114 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15115 | |
| 15116 | // When a client certificate is supplied, Connect() will not be aborted |
| 15117 | // when the peer requests the certificate. Instead, the handshake will |
| 15118 | // artificially succeed, allowing the caller to write the HTTP request to |
| 15119 | // the socket. The handshake messages are not processed until Read() is |
| 15120 | // called, which then detects that the handshake was aborted, due to the |
| 15121 | // peer sending a handshake_failure because it requires a client |
| 15122 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15123 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15124 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15125 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15126 | MockRead data2_reads[] = { |
| 15127 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15128 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15129 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15130 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15131 | |
| 15132 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15133 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 15134 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15135 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15136 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15137 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15138 | StaticSocketDataProvider data3(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15139 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15140 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15141 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 15142 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15143 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15144 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15145 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15146 | StaticSocketDataProvider data4(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15147 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15148 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15149 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15150 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15151 | ssl_data5.cert_request_info = cert_request.get(); |
| 15152 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15153 | StaticSocketDataProvider data5(data2_reads, base::span<MockWrite>()); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 15154 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 15155 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15156 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15157 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15158 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15159 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15160 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15161 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15162 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15163 | |
| 15164 | // Complete the SSL handshake, which should abort due to requiring a |
| 15165 | // client certificate. |
| 15166 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15167 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15168 | |
| 15169 | // Indicate that no certificate should be supplied. From the perspective |
| 15170 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15171 | // certificate, so this is the same as supply a |
| 15172 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15173 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15174 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15175 | |
| 15176 | // Ensure the certificate was added to the client auth cache before |
| 15177 | // allowing the connection to continue restarting. |
| 15178 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15179 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15180 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15181 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15182 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15183 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15184 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15185 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 15186 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15187 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15188 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15189 | |
| 15190 | // Ensure that the client certificate is removed from the cache on a |
| 15191 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15192 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15193 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 15194 | } |
| 15195 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15196 | // Ensure that a client certificate is removed from the SSL client auth |
| 15197 | // cache when: |
| 15198 | // 1) An HTTPS proxy is involved. |
| 15199 | // 3) The HTTPS proxy requests a client certificate. |
| 15200 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 15201 | // proxy. |
| 15202 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 15203 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15204 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15205 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 15206 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15207 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15208 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15209 | |
| 15210 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15211 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15212 | |
| 15213 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 15214 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 15215 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 15216 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15217 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15218 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15219 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15220 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15221 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15222 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15223 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15224 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15225 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15226 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15227 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15228 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15229 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 15230 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15231 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15232 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15233 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15234 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15235 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 15236 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15237 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15238 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15239 | requests[0].url = GURL("https://www.example.com/"); |
| 15240 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15241 | requests[0].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15242 | requests[0].traffic_annotation = |
| 15243 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15244 | |
| 15245 | requests[1].url = GURL("http://www.example.com/"); |
| 15246 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 15247 | requests[1].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15248 | requests[1].traffic_annotation = |
| 15249 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15250 | |
Avi Drissman | 4365a478 | 2018-12-28 19:26:24 | [diff] [blame] | 15251 | for (size_t i = 0; i < base::size(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15252 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15253 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15254 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15255 | |
| 15256 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 15257 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15258 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15259 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15260 | |
| 15261 | // Complete the SSL handshake, which should abort due to requiring a |
| 15262 | // client certificate. |
| 15263 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15264 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15265 | |
| 15266 | // Indicate that no certificate should be supplied. From the perspective |
| 15267 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 15268 | // certificate, so this is the same as supply a |
| 15269 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15270 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15271 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15272 | |
| 15273 | // Ensure the certificate was added to the client auth cache before |
| 15274 | // allowing the connection to continue restarting. |
| 15275 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15276 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15277 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15278 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15279 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15280 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 15281 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15282 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15283 | HostPortPair("www.example.com", 443), &client_cert, |
| 15284 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15285 | |
| 15286 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 15287 | // then consume ssl_data3, which should also fail. The result code is |
| 15288 | // checked against what ssl_data3 should return. |
| 15289 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15290 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15291 | |
| 15292 | // Now that the new handshake has failed, ensure that the client |
| 15293 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15294 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15295 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 15296 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 15297 | HostPortPair("www.example.com", 443), &client_cert, |
| 15298 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 15299 | } |
| 15300 | } |
| 15301 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15302 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15303 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15304 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15305 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15306 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15307 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15308 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15309 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15310 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15311 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15312 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15313 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15314 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15315 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15316 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15317 | spdy::SpdySerializedFrame host1_resp( |
| 15318 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15319 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15320 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15321 | spdy::SpdySerializedFrame host2_resp( |
| 15322 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 15323 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15324 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15325 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15326 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15327 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15328 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15329 | }; |
| 15330 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15331 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15332 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15333 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15334 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15335 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15336 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15337 | HttpRequestInfo request1; |
| 15338 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15339 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15340 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15341 | request1.traffic_annotation = |
| 15342 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15343 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15344 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15345 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15346 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15347 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15348 | |
| 15349 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15350 | ASSERT_TRUE(response); |
| 15351 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15352 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15353 | |
| 15354 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15355 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15356 | EXPECT_EQ("hello!", response_data); |
| 15357 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15358 | // Preload mail.example.com into HostCache. |
| 15359 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 15360 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15361 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 15362 | std::unique_ptr<HostResolver::Request> request; |
| 15363 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 15364 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15365 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15366 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 15367 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15368 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15369 | |
| 15370 | HttpRequestInfo request2; |
| 15371 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15372 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15373 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15374 | request2.traffic_annotation = |
| 15375 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15376 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15377 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15378 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15379 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15380 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15381 | |
| 15382 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15383 | ASSERT_TRUE(response); |
| 15384 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15385 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15386 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15387 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15388 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15389 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15390 | } |
| 15391 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15392 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15393 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15394 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15395 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15396 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15397 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15398 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15399 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15400 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15401 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15402 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15403 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15404 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15405 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15406 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15407 | spdy::SpdySerializedFrame host1_resp( |
| 15408 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15409 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15410 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15411 | spdy::SpdySerializedFrame host2_resp( |
| 15412 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 15413 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15414 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15415 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15416 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15417 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15418 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15419 | }; |
| 15420 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15421 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15422 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15423 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15424 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15425 | |
| 15426 | TestCompletionCallback callback; |
| 15427 | HttpRequestInfo request1; |
| 15428 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15429 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15430 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15431 | request1.traffic_annotation = |
| 15432 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15433 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15434 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15435 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15436 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15437 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15438 | |
| 15439 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15440 | ASSERT_TRUE(response); |
| 15441 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15442 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15443 | |
| 15444 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15445 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15446 | EXPECT_EQ("hello!", response_data); |
| 15447 | |
| 15448 | HttpRequestInfo request2; |
| 15449 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15450 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15451 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15452 | request2.traffic_annotation = |
| 15453 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15454 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15455 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15456 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15457 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15458 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15459 | |
| 15460 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15461 | ASSERT_TRUE(response); |
| 15462 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15463 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15464 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15465 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15466 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15467 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15468 | } |
| 15469 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15470 | // Regression test for https://crbug.com/546991. |
| 15471 | // The server might not be able to serve an IP pooled request, and might send a |
| 15472 | // 421 Misdirected Request response status to indicate this. |
| 15473 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 15474 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 15475 | // Two hosts resolve to the same IP address. |
| 15476 | const std::string ip_addr = "1.2.3.4"; |
| 15477 | IPAddress ip; |
| 15478 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 15479 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15480 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15481 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15482 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 15483 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 15484 | |
| 15485 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15486 | |
| 15487 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15488 | spdy::SpdySerializedFrame req1( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15489 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 15490 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15491 | spdy::SpdySerializedFrame req2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15492 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15493 | spdy::SpdySerializedFrame rst( |
| 15494 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15495 | MockWrite writes1[] = { |
| 15496 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 15497 | CreateMockWrite(rst, 6), |
| 15498 | }; |
| 15499 | |
| 15500 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15501 | spdy::SpdySerializedFrame resp1( |
| 15502 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15503 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15504 | spdy::SpdyHeaderBlock response_headers; |
| 15505 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 15506 | spdy::SpdySerializedFrame resp2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15507 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 15508 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15509 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15510 | |
| 15511 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15512 | SequencedSocketData data1(connect1, reads1, writes1); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15513 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15514 | |
| 15515 | AddSSLSocketData(); |
| 15516 | |
| 15517 | // Retry the second request on a second connection. |
| 15518 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15519 | spdy::SpdySerializedFrame req3( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15520 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15521 | MockWrite writes2[] = { |
| 15522 | CreateMockWrite(req3, 0), |
| 15523 | }; |
| 15524 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15525 | spdy::SpdySerializedFrame resp3( |
| 15526 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15527 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15528 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15529 | MockRead(ASYNC, 0, 3)}; |
| 15530 | |
| 15531 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15532 | SequencedSocketData data2(connect2, reads2, writes2); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15533 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15534 | |
| 15535 | AddSSLSocketData(); |
| 15536 | |
| 15537 | // Preload mail.example.org into HostCache. |
| 15538 | HostPortPair host_port("mail.example.org", 443); |
| 15539 | HostResolver::RequestInfo resolve_info(host_port); |
| 15540 | AddressList ignored; |
| 15541 | std::unique_ptr<HostResolver::Request> request; |
| 15542 | TestCompletionCallback callback; |
| 15543 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 15544 | &ignored, callback.callback(), |
| 15545 | &request, NetLogWithSource()); |
| 15546 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15547 | rv = callback.WaitForResult(); |
| 15548 | EXPECT_THAT(rv, IsOk()); |
| 15549 | |
| 15550 | HttpRequestInfo request1; |
| 15551 | request1.method = "GET"; |
| 15552 | request1.url = GURL("https://www.example.org/"); |
| 15553 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15554 | request1.traffic_annotation = |
| 15555 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15556 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15557 | |
| 15558 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15559 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15560 | rv = callback.WaitForResult(); |
| 15561 | EXPECT_THAT(rv, IsOk()); |
| 15562 | |
| 15563 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15564 | ASSERT_TRUE(response); |
| 15565 | ASSERT_TRUE(response->headers); |
| 15566 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15567 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15568 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15569 | std::string response_data; |
| 15570 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15571 | EXPECT_EQ("hello!", response_data); |
| 15572 | |
| 15573 | HttpRequestInfo request2; |
| 15574 | request2.method = "GET"; |
| 15575 | request2.url = GURL("https://mail.example.org/"); |
| 15576 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15577 | request2.traffic_annotation = |
| 15578 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15579 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15580 | |
| 15581 | BoundTestNetLog log; |
| 15582 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15583 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15584 | rv = callback.WaitForResult(); |
| 15585 | EXPECT_THAT(rv, IsOk()); |
| 15586 | |
| 15587 | response = trans2.GetResponseInfo(); |
| 15588 | ASSERT_TRUE(response); |
| 15589 | ASSERT_TRUE(response->headers); |
| 15590 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15591 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15592 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15593 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15594 | EXPECT_EQ("hello!", response_data); |
| 15595 | |
| 15596 | TestNetLogEntry::List entries; |
| 15597 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15598 | ExpectLogContainsSomewhere( |
| 15599 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15600 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15601 | } |
| 15602 | |
| 15603 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 15604 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 15605 | // portions of the response. |
| 15606 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 15607 | // Two hosts resolve to the same IP address. |
| 15608 | const std::string ip_addr = "1.2.3.4"; |
| 15609 | IPAddress ip; |
| 15610 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 15611 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15612 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15613 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15614 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 15615 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 15616 | |
| 15617 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 15618 | |
| 15619 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15620 | spdy::SpdySerializedFrame req1( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15621 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 15622 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15623 | spdy::SpdySerializedFrame req2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15624 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15625 | spdy::SpdySerializedFrame rst( |
| 15626 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15627 | MockWrite writes1[] = { |
| 15628 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 15629 | CreateMockWrite(rst, 6), |
| 15630 | }; |
| 15631 | |
| 15632 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15633 | spdy::SpdySerializedFrame resp1( |
| 15634 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 15635 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 15636 | spdy::SpdyHeaderBlock response_headers; |
| 15637 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 15638 | spdy::SpdySerializedFrame resp2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15639 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 15640 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 15641 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 15642 | |
| 15643 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15644 | SequencedSocketData data1(connect1, reads1, writes1); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15645 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15646 | |
| 15647 | AddSSLSocketData(); |
| 15648 | |
| 15649 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 15650 | // Retry again. |
| 15651 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15652 | spdy::SpdySerializedFrame req3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15653 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 15654 | MockWrite writes2[] = { |
| 15655 | CreateMockWrite(req3, 0), |
| 15656 | }; |
| 15657 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15658 | spdy::SpdySerializedFrame resp3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15659 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15660 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15661 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 15662 | MockRead(ASYNC, 0, 3)}; |
| 15663 | |
| 15664 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15665 | SequencedSocketData data2(connect2, reads2, writes2); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15666 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 15667 | |
| 15668 | AddSSLSocketData(); |
| 15669 | |
| 15670 | // Preload mail.example.org into HostCache. |
| 15671 | HostPortPair host_port("mail.example.org", 443); |
| 15672 | HostResolver::RequestInfo resolve_info(host_port); |
| 15673 | AddressList ignored; |
| 15674 | std::unique_ptr<HostResolver::Request> request; |
| 15675 | TestCompletionCallback callback; |
| 15676 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 15677 | &ignored, callback.callback(), |
| 15678 | &request, NetLogWithSource()); |
| 15679 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15680 | rv = callback.WaitForResult(); |
| 15681 | EXPECT_THAT(rv, IsOk()); |
| 15682 | |
| 15683 | HttpRequestInfo request1; |
| 15684 | request1.method = "GET"; |
| 15685 | request1.url = GURL("https://www.example.org/"); |
| 15686 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15687 | request1.traffic_annotation = |
| 15688 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15689 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15690 | |
| 15691 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 15692 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15693 | rv = callback.WaitForResult(); |
| 15694 | EXPECT_THAT(rv, IsOk()); |
| 15695 | |
| 15696 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 15697 | ASSERT_TRUE(response); |
| 15698 | ASSERT_TRUE(response->headers); |
| 15699 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 15700 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15701 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15702 | std::string response_data; |
| 15703 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 15704 | EXPECT_EQ("hello!", response_data); |
| 15705 | |
| 15706 | HttpRequestInfo request2; |
| 15707 | request2.method = "GET"; |
| 15708 | request2.url = GURL("https://mail.example.org/"); |
| 15709 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15710 | request2.traffic_annotation = |
| 15711 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 15712 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15713 | |
| 15714 | BoundTestNetLog log; |
| 15715 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 15716 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15717 | rv = callback.WaitForResult(); |
| 15718 | EXPECT_THAT(rv, IsOk()); |
| 15719 | |
| 15720 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 15721 | // caller. |
| 15722 | response = trans2.GetResponseInfo(); |
| 15723 | ASSERT_TRUE(response); |
| 15724 | ASSERT_TRUE(response->headers); |
| 15725 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 15726 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 15727 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 15728 | EXPECT_TRUE(response->ssl_info.cert); |
| 15729 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 15730 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 15731 | } |
| 15732 | |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15733 | class OneTimeCachingHostResolver : public MockHostResolverBase { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15734 | public: |
| 15735 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15736 | : MockHostResolverBase(/* use_caching = */ true), host_port_(host_port) {} |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 15737 | ~OneTimeCachingHostResolver() override = default; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15738 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 15739 | int ResolveFromCache(const RequestInfo& info, |
| 15740 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15741 | const NetLogWithSource& net_log) override { |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15742 | int rv = MockHostResolverBase::ResolveFromCache(info, addresses, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 15743 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15744 | GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15745 | return rv; |
| 15746 | } |
| 15747 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15748 | private: |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15749 | const HostPortPair host_port_; |
| 15750 | }; |
| 15751 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15752 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 15753 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15754 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15755 | session_deps_.host_resolver = std::make_unique<OneTimeCachingHostResolver>( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15756 | HostPortPair("mail.example.com", 443)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15757 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15758 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 15759 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15760 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15761 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15762 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15763 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15764 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15765 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15766 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15767 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15768 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15769 | spdy::SpdySerializedFrame host1_resp( |
| 15770 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15771 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15772 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15773 | spdy::SpdySerializedFrame host2_resp( |
| 15774 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 15775 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15776 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15777 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15778 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 15779 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15780 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15781 | }; |
| 15782 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 15783 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 15784 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15785 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15786 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15787 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15788 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15789 | HttpRequestInfo request1; |
| 15790 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15791 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15792 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15793 | request1.traffic_annotation = |
| 15794 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15795 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15796 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15797 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15798 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15799 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15800 | |
| 15801 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15802 | ASSERT_TRUE(response); |
| 15803 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15804 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15805 | |
| 15806 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15807 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15808 | EXPECT_EQ("hello!", response_data); |
| 15809 | |
| 15810 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15811 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15812 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 15813 | std::unique_ptr<HostResolver::Request> request; |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15814 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 15815 | &ignored, callback.callback(), |
| 15816 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15817 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 15818 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15819 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15820 | |
| 15821 | HttpRequestInfo request2; |
| 15822 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15823 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15824 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15825 | request2.traffic_annotation = |
| 15826 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15827 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15828 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15829 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15830 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15831 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15832 | |
| 15833 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15834 | ASSERT_TRUE(response); |
| 15835 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15836 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15837 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15838 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15839 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15840 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15841 | } |
| 15842 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15843 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15844 | const std::string https_url = "https://www.example.org:8080/"; |
| 15845 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15846 | |
| 15847 | // SPDY GET for HTTPS URL |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15848 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15849 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15850 | |
| 15851 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15852 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15853 | }; |
| 15854 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15855 | spdy::SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15856 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15857 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15858 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15859 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15860 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15861 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15862 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15863 | |
| 15864 | // HTTP GET for the HTTP URL |
| 15865 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15866 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15867 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15868 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15869 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15870 | }; |
| 15871 | |
| 15872 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15873 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 15874 | MockRead(ASYNC, 2, "hello"), |
| 15875 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15876 | }; |
| 15877 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15878 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15879 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15880 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15881 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15882 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15883 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15884 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15885 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15886 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15887 | |
| 15888 | // Start the first transaction to set up the SpdySession |
| 15889 | HttpRequestInfo request1; |
| 15890 | request1.method = "GET"; |
| 15891 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15892 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15893 | request1.traffic_annotation = |
| 15894 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15895 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15896 | TestCompletionCallback callback1; |
| 15897 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15898 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15899 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15900 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15901 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15902 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15903 | |
| 15904 | // Now, start the HTTP request |
| 15905 | HttpRequestInfo request2; |
| 15906 | request2.method = "GET"; |
| 15907 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15908 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15909 | request2.traffic_annotation = |
| 15910 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15911 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15912 | TestCompletionCallback callback2; |
| 15913 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15914 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15915 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15916 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15917 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15918 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15919 | } |
| 15920 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15921 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 15922 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15923 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15924 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 15925 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15926 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15927 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15928 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15929 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15930 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15931 | |
| 15932 | // No data should be read from the alternative, because HTTP/1.1 is |
| 15933 | // negotiated. |
| 15934 | StaticSocketDataProvider data; |
| 15935 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15936 | |
| 15937 | // 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] | 15938 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15939 | // mocked. This way the request relies on the alternate Job. |
| 15940 | StaticSocketDataProvider data_refused; |
| 15941 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 15942 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 15943 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15944 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15945 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15946 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15947 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15948 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15949 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15950 | http_server_properties->SetHttp2AlternativeService( |
| 15951 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15952 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15953 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15954 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15955 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15956 | request.url = GURL("https://www.example.org:443"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15957 | request.traffic_annotation = |
| 15958 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15959 | TestCompletionCallback callback; |
| 15960 | |
| 15961 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15962 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15963 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15964 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15965 | } |
| 15966 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15967 | // 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] | 15968 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15969 | // succeeds, the request should succeed, even if the latter fails because |
| 15970 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15971 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15972 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 15973 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15974 | |
| 15975 | // Negotiate HTTP/1.1 with alternative. |
| 15976 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15977 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15978 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 15979 | |
| 15980 | // No data should be read from the alternative, because HTTP/1.1 is |
| 15981 | // negotiated. |
| 15982 | StaticSocketDataProvider data; |
| 15983 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15984 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15985 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15986 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15987 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15988 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 15989 | |
| 15990 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15991 | MockWrite("GET / HTTP/1.1\r\n" |
| 15992 | "Host: www.example.org\r\n" |
| 15993 | "Connection: keep-alive\r\n\r\n"), |
| 15994 | MockWrite("GET /second HTTP/1.1\r\n" |
| 15995 | "Host: www.example.org\r\n" |
| 15996 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15997 | }; |
| 15998 | |
| 15999 | MockRead http_reads[] = { |
| 16000 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16001 | MockRead("Content-Type: text/html\r\n"), |
| 16002 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16003 | MockRead("foobar"), |
| 16004 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16005 | MockRead("Content-Type: text/html\r\n"), |
| 16006 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16007 | MockRead("another"), |
| 16008 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16009 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16010 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16011 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16012 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16013 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16014 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16015 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16016 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16017 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16018 | http_server_properties->SetHttp2AlternativeService( |
| 16019 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16020 | |
| 16021 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 16022 | HttpRequestInfo request1; |
| 16023 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16024 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16025 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16026 | request1.traffic_annotation = |
| 16027 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16028 | TestCompletionCallback callback1; |
| 16029 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16030 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16031 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16032 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16033 | |
| 16034 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16035 | ASSERT_TRUE(response1); |
| 16036 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16037 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 16038 | |
| 16039 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16040 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16041 | EXPECT_EQ("foobar", response_data1); |
| 16042 | |
| 16043 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 16044 | // for alternative service. |
| 16045 | EXPECT_TRUE( |
| 16046 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 16047 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16048 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16049 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16050 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16051 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 16052 | HttpRequestInfo request2; |
| 16053 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 16054 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16055 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16056 | request2.traffic_annotation = |
| 16057 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16058 | TestCompletionCallback callback2; |
| 16059 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16060 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16061 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16062 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16063 | |
| 16064 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16065 | ASSERT_TRUE(response2); |
| 16066 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16067 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 16068 | |
| 16069 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16070 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 16071 | EXPECT_EQ("another", response_data2); |
| 16072 | } |
| 16073 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16074 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 16075 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 16076 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16077 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16078 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16079 | HostPortPair alternative("alternative.example.org", 443); |
| 16080 | std::string origin_url = "https://origin.example.org:443"; |
| 16081 | std::string alternative_url = "https://alternative.example.org:443"; |
| 16082 | |
| 16083 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 16084 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16085 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16086 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16087 | |
| 16088 | // HTTP/1.1 data for |request1| and |request2|. |
| 16089 | MockWrite http_writes[] = { |
| 16090 | MockWrite( |
| 16091 | "GET / HTTP/1.1\r\n" |
| 16092 | "Host: alternative.example.org\r\n" |
| 16093 | "Connection: keep-alive\r\n\r\n"), |
| 16094 | MockWrite( |
| 16095 | "GET / HTTP/1.1\r\n" |
| 16096 | "Host: alternative.example.org\r\n" |
| 16097 | "Connection: keep-alive\r\n\r\n"), |
| 16098 | }; |
| 16099 | |
| 16100 | MockRead http_reads[] = { |
| 16101 | MockRead( |
| 16102 | "HTTP/1.1 200 OK\r\n" |
| 16103 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16104 | "Content-Length: 40\r\n\r\n" |
| 16105 | "first HTTP/1.1 response from alternative"), |
| 16106 | MockRead( |
| 16107 | "HTTP/1.1 200 OK\r\n" |
| 16108 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 16109 | "Content-Length: 41\r\n\r\n" |
| 16110 | "second HTTP/1.1 response from alternative"), |
| 16111 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16112 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16113 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16114 | |
| 16115 | // This test documents that an alternate Job should not pool to an already |
| 16116 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16117 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16118 | StaticSocketDataProvider data_refused; |
| 16119 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 16120 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 16121 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 16122 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16123 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 16124 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16125 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 16126 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 16127 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 16128 | http_server_properties->SetHttp2AlternativeService( |
| 16129 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16130 | |
| 16131 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16132 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16133 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16134 | request1.method = "GET"; |
| 16135 | request1.url = GURL(alternative_url); |
| 16136 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16137 | request1.traffic_annotation = |
| 16138 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16139 | TestCompletionCallback callback1; |
| 16140 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16141 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16142 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16143 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16144 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16145 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16146 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16147 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16148 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 16149 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16150 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16151 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 16152 | |
| 16153 | // Request for origin.example.org, which has an alternative service. This |
| 16154 | // will start two Jobs: the alternative looks for connections to pool to, |
| 16155 | // 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] | 16156 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16157 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16158 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16159 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16160 | request2.method = "GET"; |
| 16161 | request2.url = GURL(origin_url); |
| 16162 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16163 | request2.traffic_annotation = |
| 16164 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16165 | TestCompletionCallback callback2; |
| 16166 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16167 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16168 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16169 | |
| 16170 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 16171 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16172 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 16173 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16174 | request3.method = "GET"; |
| 16175 | request3.url = GURL(alternative_url); |
| 16176 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16177 | request3.traffic_annotation = |
| 16178 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16179 | TestCompletionCallback callback3; |
| 16180 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16181 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16182 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16183 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16184 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16185 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16186 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16187 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16188 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 16189 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16190 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 16191 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 16192 | } |
| 16193 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16194 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16195 | const std::string https_url = "https://www.example.org:8080/"; |
| 16196 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16197 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16198 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16199 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16200 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16201 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16202 | const HostPortPair host_port_pair("www.example.org", 8080); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16203 | spdy::SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 16204 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16205 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16206 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16207 | spdy::SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 16208 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 16209 | |
| 16210 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16211 | spdy::SpdyHeaderBlock req2_block; |
| 16212 | req2_block[spdy::kHttp2MethodHeader] = "GET"; |
| 16213 | req2_block[spdy::kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 16214 | req2_block[spdy::kHttp2SchemeHeader] = "http"; |
| 16215 | req2_block[spdy::kHttp2PathHeader] = "/"; |
| 16216 | spdy::SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16217 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16218 | |
| 16219 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16220 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 16221 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16222 | }; |
| 16223 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16224 | spdy::SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16225 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16226 | spdy::SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16227 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16228 | spdy::SpdySerializedFrame body1( |
| 16229 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 16230 | spdy::SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16231 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16232 | spdy::SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16233 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16234 | spdy::SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 16235 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16236 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16237 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16238 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16239 | CreateMockRead(wrapped_resp1, 4), |
| 16240 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16241 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16242 | CreateMockRead(resp2, 8), |
| 16243 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16244 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 16245 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16246 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16247 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16248 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 16249 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16250 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16251 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16252 | ProxyResolutionService::CreateFixedFromPacResult( |
| 16253 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 16254 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16255 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16256 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16257 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16258 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16259 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16260 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16261 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16262 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16263 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16264 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16265 | |
| 16266 | // Start the first transaction to set up the SpdySession |
| 16267 | HttpRequestInfo request1; |
| 16268 | request1.method = "GET"; |
| 16269 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16270 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16271 | request1.traffic_annotation = |
| 16272 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16273 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16274 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16275 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16276 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16277 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16278 | data1.RunUntilPaused(); |
| 16279 | base::RunLoop().RunUntilIdle(); |
| 16280 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16281 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16282 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16283 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16284 | LoadTimingInfo load_timing_info1; |
| 16285 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 16286 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 16287 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 16288 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16289 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16290 | HttpRequestInfo request2; |
| 16291 | request2.method = "GET"; |
| 16292 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16293 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16294 | request2.traffic_annotation = |
| 16295 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16296 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16297 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16298 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16299 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16300 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16301 | data1.RunUntilPaused(); |
| 16302 | base::RunLoop().RunUntilIdle(); |
| 16303 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16304 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16305 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 16306 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 16307 | |
| 16308 | LoadTimingInfo load_timing_info2; |
| 16309 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 16310 | // The established SPDY sessions is considered reused by the HTTP request. |
| 16311 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 16312 | // HTTP requests over a SPDY session should have a different connection |
| 16313 | // socket_log_id than requests over a tunnel. |
| 16314 | 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] | 16315 | } |
| 16316 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16317 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 16318 | // that we do not pool other origins that resolve to the same IP when |
| 16319 | // the certificate does not match the new origin. |
| 16320 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16321 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16322 | const std::string url1 = "http://www.example.org/"; |
| 16323 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16324 | const std::string ip_addr = "1.2.3.4"; |
| 16325 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16326 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16327 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16328 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16329 | // SPDY GET for HTTP URL (through SPDY proxy) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16330 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16331 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16332 | spdy::SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 16333 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16334 | |
| 16335 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16336 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16337 | }; |
| 16338 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16339 | spdy::SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 16340 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16341 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16342 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 16343 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16344 | }; |
| 16345 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16346 | SequencedSocketData data1(reads1, writes1); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 16347 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 16348 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16349 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 16350 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16351 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16352 | |
| 16353 | // SPDY GET for HTTPS URL (direct) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16354 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16355 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16356 | |
| 16357 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16358 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16359 | }; |
| 16360 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16361 | spdy::SpdySerializedFrame resp2( |
| 16362 | spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
| 16363 | spdy::SpdySerializedFrame body2( |
| 16364 | spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16365 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16366 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16367 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16368 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16369 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16370 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16371 | |
| 16372 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 16373 | // all others direct. |
| 16374 | ProxyConfig proxy_config; |
| 16375 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16376 | session_deps_.proxy_resolution_service = |
| 16377 | std::make_unique<ProxyResolutionService>( |
| 16378 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 16379 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 16380 | nullptr, nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16381 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16382 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16383 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16384 | // Load a valid cert. Note, that this does not need to |
| 16385 | // be valid for proxy because the MockSSLClientSocket does |
| 16386 | // not actually verify it. But SpdySession will use this |
| 16387 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 16388 | ssl1.ssl_info.cert = |
| 16389 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 16390 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16391 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16392 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16393 | |
| 16394 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16395 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16396 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16397 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16398 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16399 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16400 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 16401 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16402 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16403 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16404 | |
| 16405 | // Start the first transaction to set up the SpdySession |
| 16406 | HttpRequestInfo request1; |
| 16407 | request1.method = "GET"; |
| 16408 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16409 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16410 | request1.traffic_annotation = |
| 16411 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16412 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16413 | TestCompletionCallback callback1; |
| 16414 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16415 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 16416 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 16417 | data1.RunUntilPaused(); |
| 16418 | base::RunLoop().RunUntilIdle(); |
| 16419 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16420 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16421 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16422 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 16423 | |
| 16424 | // Now, start the HTTP request |
| 16425 | HttpRequestInfo request2; |
| 16426 | request2.method = "GET"; |
| 16427 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16428 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16429 | request2.traffic_annotation = |
| 16430 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16431 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16432 | TestCompletionCallback callback2; |
| 16433 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16434 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 16435 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16436 | |
| 16437 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16438 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 16439 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16440 | } |
| 16441 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16442 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 16443 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 16444 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 16445 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16446 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16447 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16448 | |
| 16449 | MockRead reads1[] = { |
| 16450 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 16451 | }; |
| 16452 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16453 | SequencedSocketData data1(reads1, base::span<MockWrite>()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16454 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16455 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16456 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16457 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16458 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16459 | }; |
| 16460 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16461 | spdy::SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 16462 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16463 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16464 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 16465 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16466 | }; |
| 16467 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16468 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16469 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16470 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16471 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16472 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16473 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16474 | |
| 16475 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16476 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16477 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16478 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16479 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16480 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 16481 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16482 | |
| 16483 | // Start the first transaction to set up the SpdySession and verify that |
| 16484 | // connection was closed. |
| 16485 | HttpRequestInfo request1; |
| 16486 | request1.method = "GET"; |
| 16487 | request1.url = GURL(https_url); |
| 16488 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16489 | request1.traffic_annotation = |
| 16490 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16491 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16492 | TestCompletionCallback callback1; |
| 16493 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16494 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16495 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16496 | |
| 16497 | // Now, start the second request and make sure it succeeds. |
| 16498 | HttpRequestInfo request2; |
| 16499 | request2.method = "GET"; |
| 16500 | request2.url = GURL(https_url); |
| 16501 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16502 | request2.traffic_annotation = |
| 16503 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 16504 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16505 | TestCompletionCallback callback2; |
| 16506 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16507 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16508 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16509 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 16510 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 16511 | } |
| 16512 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16513 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16514 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16515 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16516 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16517 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16518 | |
| 16519 | // Use two different hosts with different IPs so they don't get pooled. |
| 16520 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 16521 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16522 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16523 | |
| 16524 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16525 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16526 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 16527 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16528 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 16529 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 16530 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16531 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16532 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16533 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16534 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16535 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16536 | spdy::SpdySerializedFrame host1_resp( |
| 16537 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 16538 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16539 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16540 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16541 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16542 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16543 | }; |
| 16544 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 16545 | // Use a separate test instance for the separate SpdySession that will be |
| 16546 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16547 | SpdyTestUtil spdy_util_2; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16548 | SequencedSocketData spdy1_data(spdy1_reads, spdy1_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 16549 | session_deps_.socket_factory->AddSocketDataProvider(&spdy1_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16550 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16551 | spdy::SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 16552 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16553 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16554 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16555 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 16556 | spdy::SpdySerializedFrame host2_resp( |
| 16557 | spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
| 16558 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16559 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16560 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 16561 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 16562 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16563 | }; |
| 16564 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16565 | SequencedSocketData spdy2_data(spdy2_reads, spdy2_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 16566 | session_deps_.socket_factory->AddSocketDataProvider(&spdy2_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16567 | |
| 16568 | MockWrite http_write[] = { |
| 16569 | MockWrite("GET / HTTP/1.1\r\n" |
| 16570 | "Host: www.a.com\r\n" |
| 16571 | "Connection: keep-alive\r\n\r\n"), |
| 16572 | }; |
| 16573 | |
| 16574 | MockRead http_read[] = { |
| 16575 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16576 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 16577 | MockRead("Content-Length: 6\r\n\r\n"), |
| 16578 | MockRead("hello!"), |
| 16579 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16580 | StaticSocketDataProvider http_data(http_read, http_write); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16581 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16582 | |
| 16583 | HostPortPair host_port_pair_a("www.a.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16584 | SpdySessionKey spdy_session_key_a( |
| 16585 | host_port_pair_a, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16586 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16587 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16588 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16589 | |
| 16590 | TestCompletionCallback callback; |
| 16591 | HttpRequestInfo request1; |
| 16592 | request1.method = "GET"; |
| 16593 | request1.url = GURL("https://www.a.com/"); |
| 16594 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16595 | request1.traffic_annotation = |
| 16596 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16597 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16598 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16599 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16600 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16601 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16602 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16603 | |
| 16604 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16605 | ASSERT_TRUE(response); |
| 16606 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16607 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16608 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16609 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16610 | |
| 16611 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16612 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16613 | EXPECT_EQ("hello!", response_data); |
| 16614 | trans.reset(); |
| 16615 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16616 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16617 | |
| 16618 | HostPortPair host_port_pair_b("www.b.com", 443); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16619 | SpdySessionKey spdy_session_key_b( |
| 16620 | host_port_pair_b, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16621 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16622 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16623 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16624 | HttpRequestInfo request2; |
| 16625 | request2.method = "GET"; |
| 16626 | request2.url = GURL("https://www.b.com/"); |
| 16627 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16628 | request2.traffic_annotation = |
| 16629 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16630 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16631 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16632 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16633 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16634 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16635 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16636 | |
| 16637 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16638 | ASSERT_TRUE(response); |
| 16639 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 16640 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16641 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16642 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16643 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16644 | EXPECT_EQ("hello!", response_data); |
| 16645 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16646 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16647 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16648 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16649 | |
| 16650 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Matt Menke | 2436b2f | 2018-12-11 18:07:11 | [diff] [blame] | 16651 | SpdySessionKey spdy_session_key_a1( |
| 16652 | host_port_pair_a1, ProxyServer::Direct(), PRIVACY_MODE_DISABLED, |
| 16653 | SpdySessionKey::IsProxySession::kFalse, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16654 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16655 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16656 | HttpRequestInfo request3; |
| 16657 | request3.method = "GET"; |
| 16658 | request3.url = GURL("http://www.a.com/"); |
| 16659 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16660 | request3.traffic_annotation = |
| 16661 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16662 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16663 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16664 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16665 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16666 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 16667 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16668 | |
| 16669 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16670 | ASSERT_TRUE(response); |
| 16671 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16672 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 16673 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 16674 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16675 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16676 | EXPECT_EQ("hello!", response_data); |
| 16677 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16678 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16679 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 16680 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 16681 | } |
| 16682 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16683 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16684 | HttpRequestInfo request; |
| 16685 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16686 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16687 | request.traffic_annotation = |
| 16688 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16689 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16690 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16691 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16692 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16693 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16694 | StaticSocketDataProvider data; |
| 16695 | data.set_connect_data(mock_connect); |
| 16696 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16697 | |
| 16698 | TestCompletionCallback callback; |
| 16699 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16700 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16701 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16702 | |
| 16703 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16704 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16705 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16706 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16707 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16708 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16709 | |
| 16710 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16711 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16712 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16713 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16714 | |
| 16715 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16716 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16717 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16718 | } |
| 16719 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16720 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16721 | HttpRequestInfo request; |
| 16722 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16723 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16724 | request.traffic_annotation = |
| 16725 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16726 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16727 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16728 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16729 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16730 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16731 | StaticSocketDataProvider data; |
| 16732 | data.set_connect_data(mock_connect); |
| 16733 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16734 | |
| 16735 | TestCompletionCallback callback; |
| 16736 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16737 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16738 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16739 | |
| 16740 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16741 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16742 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16743 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 16744 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16745 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16746 | |
| 16747 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16748 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 16749 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16750 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16751 | |
| 16752 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16753 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 16754 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16755 | } |
| 16756 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16757 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16758 | HttpRequestInfo request; |
| 16759 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16760 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16761 | request.traffic_annotation = |
| 16762 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16763 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16764 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16765 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16766 | |
| 16767 | MockWrite data_writes[] = { |
| 16768 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16769 | }; |
| 16770 | MockRead data_reads[] = { |
| 16771 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16772 | }; |
| 16773 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16774 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16775 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16776 | |
| 16777 | TestCompletionCallback callback; |
| 16778 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16779 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16780 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16781 | |
| 16782 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16783 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16784 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16785 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16786 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16787 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16788 | } |
| 16789 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16790 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16791 | HttpRequestInfo request; |
| 16792 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16793 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16794 | request.traffic_annotation = |
| 16795 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16796 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16797 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16798 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16799 | |
| 16800 | MockWrite data_writes[] = { |
| 16801 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 16802 | }; |
| 16803 | MockRead data_reads[] = { |
| 16804 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16805 | }; |
| 16806 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16807 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16808 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16809 | |
| 16810 | TestCompletionCallback callback; |
| 16811 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16812 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16813 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16814 | |
| 16815 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16816 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16817 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16818 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16819 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16820 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16821 | } |
| 16822 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16823 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16824 | HttpRequestInfo request; |
| 16825 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16826 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16827 | request.traffic_annotation = |
| 16828 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16829 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16830 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16831 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16832 | |
| 16833 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16834 | MockWrite( |
| 16835 | "GET / HTTP/1.1\r\n" |
| 16836 | "Host: www.example.org\r\n" |
| 16837 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16838 | }; |
| 16839 | MockRead data_reads[] = { |
| 16840 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16841 | }; |
| 16842 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16843 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16844 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16845 | |
| 16846 | TestCompletionCallback callback; |
| 16847 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16848 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16849 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16850 | |
| 16851 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16852 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16853 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16854 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16855 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16856 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16857 | } |
| 16858 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16859 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16860 | HttpRequestInfo request; |
| 16861 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16862 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16863 | request.traffic_annotation = |
| 16864 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16865 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16866 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16867 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16868 | |
| 16869 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16870 | MockWrite( |
| 16871 | "GET / HTTP/1.1\r\n" |
| 16872 | "Host: www.example.org\r\n" |
| 16873 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16874 | }; |
| 16875 | MockRead data_reads[] = { |
| 16876 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 16877 | }; |
| 16878 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16879 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16880 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16881 | |
| 16882 | TestCompletionCallback callback; |
| 16883 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16884 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16885 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16886 | |
| 16887 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16888 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16889 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16890 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16891 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16892 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16893 | } |
| 16894 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16895 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16896 | HttpRequestInfo request; |
| 16897 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16898 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16899 | request.extra_headers.SetHeader("X-Foo", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16900 | request.traffic_annotation = |
| 16901 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16902 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16903 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16904 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16905 | |
| 16906 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16907 | MockWrite( |
| 16908 | "GET / HTTP/1.1\r\n" |
| 16909 | "Host: www.example.org\r\n" |
| 16910 | "Connection: keep-alive\r\n" |
| 16911 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16912 | }; |
| 16913 | MockRead data_reads[] = { |
| 16914 | MockRead("HTTP/1.1 200 OK\r\n" |
| 16915 | "Content-Length: 5\r\n\r\n" |
| 16916 | "hello"), |
| 16917 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 16918 | }; |
| 16919 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16920 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16921 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16922 | |
| 16923 | TestCompletionCallback callback; |
| 16924 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16925 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16926 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16927 | |
| 16928 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16929 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16930 | |
| 16931 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16932 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16933 | std::string foo; |
| 16934 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 16935 | EXPECT_EQ("bar", foo); |
| 16936 | } |
| 16937 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16938 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 16939 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16940 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16941 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16942 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16943 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16944 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16945 | |
| 16946 | // Set up SSL request. |
| 16947 | |
| 16948 | HttpRequestInfo ssl_request; |
| 16949 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16950 | ssl_request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16951 | ssl_request.traffic_annotation = |
| 16952 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16953 | |
| 16954 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16955 | MockWrite( |
| 16956 | "GET / HTTP/1.1\r\n" |
| 16957 | "Host: www.example.org\r\n" |
| 16958 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16959 | }; |
| 16960 | MockRead ssl_reads[] = { |
| 16961 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16962 | MockRead("Content-Length: 11\r\n\r\n"), |
| 16963 | MockRead("hello world"), |
| 16964 | MockRead(SYNCHRONOUS, OK), |
| 16965 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16966 | StaticSocketDataProvider ssl_data(ssl_reads, ssl_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16967 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16968 | |
| 16969 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16970 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16971 | |
| 16972 | // Set up HTTP request. |
| 16973 | |
| 16974 | HttpRequestInfo http_request; |
| 16975 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16976 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16977 | http_request.traffic_annotation = |
| 16978 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16979 | |
| 16980 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16981 | MockWrite( |
| 16982 | "GET / HTTP/1.1\r\n" |
| 16983 | "Host: www.example.org\r\n" |
| 16984 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16985 | }; |
| 16986 | MockRead http_reads[] = { |
| 16987 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16988 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16989 | MockRead("falafel"), |
| 16990 | MockRead(SYNCHRONOUS, OK), |
| 16991 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16992 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16993 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16994 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16995 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16996 | |
| 16997 | // Start the SSL request. |
| 16998 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16999 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17000 | ASSERT_EQ(ERR_IO_PENDING, |
| 17001 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 17002 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17003 | |
| 17004 | // Start the HTTP request. Pool should stall. |
| 17005 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17006 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17007 | ASSERT_EQ(ERR_IO_PENDING, |
| 17008 | http_trans.Start(&http_request, http_callback.callback(), |
| 17009 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17010 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17011 | |
| 17012 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17013 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17014 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17015 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17016 | EXPECT_EQ("hello world", response_data); |
| 17017 | |
| 17018 | // The SSL socket should automatically be closed, so the HTTP request can |
| 17019 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17020 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 17021 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17022 | |
| 17023 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17024 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17025 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17026 | EXPECT_EQ("falafel", response_data); |
| 17027 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17028 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17029 | } |
| 17030 | |
| 17031 | // Tests that when a SSL connection is established but there's no corresponding |
| 17032 | // request that needs it, the new socket is closed if the transport socket pool |
| 17033 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17034 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17035 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 17036 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17037 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 17038 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 17039 | |
| 17040 | // Set up an ssl request. |
| 17041 | |
| 17042 | HttpRequestInfo ssl_request; |
| 17043 | ssl_request.method = "GET"; |
| 17044 | ssl_request.url = GURL("https://www.foopy.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17045 | ssl_request.traffic_annotation = |
| 17046 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17047 | |
| 17048 | // No data will be sent on the SSL socket. |
| 17049 | StaticSocketDataProvider ssl_data; |
| 17050 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 17051 | |
| 17052 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17053 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17054 | |
| 17055 | // Set up HTTP request. |
| 17056 | |
| 17057 | HttpRequestInfo http_request; |
| 17058 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17059 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17060 | http_request.traffic_annotation = |
| 17061 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17062 | |
| 17063 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17064 | MockWrite( |
| 17065 | "GET / HTTP/1.1\r\n" |
| 17066 | "Host: www.example.org\r\n" |
| 17067 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17068 | }; |
| 17069 | MockRead http_reads[] = { |
| 17070 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 17071 | MockRead("Content-Length: 7\r\n\r\n"), |
| 17072 | MockRead("falafel"), |
| 17073 | MockRead(SYNCHRONOUS, OK), |
| 17074 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17075 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17076 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 17077 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17078 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17079 | |
| 17080 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 17081 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 17082 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 17083 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17084 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17085 | |
| 17086 | // Start the HTTP request. Pool should stall. |
| 17087 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17088 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17089 | ASSERT_EQ(ERR_IO_PENDING, |
| 17090 | http_trans.Start(&http_request, http_callback.callback(), |
| 17091 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17092 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17093 | |
| 17094 | // The SSL connection will automatically be closed once the connection is |
| 17095 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17096 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17097 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17098 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17099 | EXPECT_EQ("falafel", response_data); |
| 17100 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 17101 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 17102 | } |
| 17103 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17104 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17105 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17106 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17107 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17108 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17109 | |
| 17110 | HttpRequestInfo request; |
| 17111 | request.method = "POST"; |
| 17112 | request.url = GURL("http://www.foo.com/"); |
| 17113 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17114 | request.traffic_annotation = |
| 17115 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17116 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17117 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17118 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17119 | // Send headers successfully, but get an error while sending the body. |
| 17120 | MockWrite data_writes[] = { |
| 17121 | MockWrite("POST / HTTP/1.1\r\n" |
| 17122 | "Host: www.foo.com\r\n" |
| 17123 | "Connection: keep-alive\r\n" |
| 17124 | "Content-Length: 3\r\n\r\n"), |
| 17125 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17126 | }; |
| 17127 | |
| 17128 | MockRead data_reads[] = { |
| 17129 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17130 | MockRead("hello world"), |
| 17131 | MockRead(SYNCHRONOUS, OK), |
| 17132 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17133 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17134 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17135 | |
| 17136 | TestCompletionCallback callback; |
| 17137 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17138 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17139 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17140 | |
| 17141 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17142 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17143 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17144 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17145 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17146 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17147 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17148 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17149 | |
| 17150 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17151 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17152 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17153 | EXPECT_EQ("hello world", response_data); |
| 17154 | } |
| 17155 | |
| 17156 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 17157 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17158 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17159 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17160 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17161 | MockWrite data_writes[] = { |
| 17162 | MockWrite("GET / HTTP/1.1\r\n" |
| 17163 | "Host: www.foo.com\r\n" |
| 17164 | "Connection: keep-alive\r\n\r\n"), |
| 17165 | MockWrite("POST / HTTP/1.1\r\n" |
| 17166 | "Host: www.foo.com\r\n" |
| 17167 | "Connection: keep-alive\r\n" |
| 17168 | "Content-Length: 3\r\n\r\n"), |
| 17169 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17170 | }; |
| 17171 | |
| 17172 | MockRead data_reads[] = { |
| 17173 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 17174 | "Content-Length: 14\r\n\r\n"), |
| 17175 | MockRead("first response"), |
| 17176 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 17177 | "Content-Length: 15\r\n\r\n"), |
| 17178 | MockRead("second response"), |
| 17179 | MockRead(SYNCHRONOUS, OK), |
| 17180 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17181 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17182 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17183 | |
| 17184 | TestCompletionCallback callback; |
| 17185 | HttpRequestInfo request1; |
| 17186 | request1.method = "GET"; |
| 17187 | request1.url = GURL("http://www.foo.com/"); |
| 17188 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17189 | request1.traffic_annotation = |
| 17190 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17191 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17192 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17193 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17194 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17195 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17196 | |
| 17197 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17198 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17199 | |
| 17200 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17201 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17202 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17203 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17204 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 17205 | |
| 17206 | std::string response_data1; |
| 17207 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17208 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17209 | EXPECT_EQ("first response", response_data1); |
| 17210 | // Delete the transaction to release the socket back into the socket pool. |
| 17211 | trans1.reset(); |
| 17212 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17213 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17214 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17215 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17216 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17217 | |
| 17218 | HttpRequestInfo request2; |
| 17219 | request2.method = "POST"; |
| 17220 | request2.url = GURL("http://www.foo.com/"); |
| 17221 | request2.upload_data_stream = &upload_data_stream; |
| 17222 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17223 | request2.traffic_annotation = |
| 17224 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17225 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17226 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17227 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17228 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17229 | |
| 17230 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17231 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17232 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17233 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17234 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17235 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17236 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17237 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 17238 | |
| 17239 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17240 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17241 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17242 | EXPECT_EQ("second response", response_data2); |
| 17243 | } |
| 17244 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17245 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17246 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17247 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17248 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17249 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17250 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17251 | |
| 17252 | HttpRequestInfo request; |
| 17253 | request.method = "POST"; |
| 17254 | request.url = GURL("http://www.foo.com/"); |
| 17255 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17256 | request.traffic_annotation = |
| 17257 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17258 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17259 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17260 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17261 | // Send headers successfully, but get an error while sending the body. |
| 17262 | MockWrite data_writes[] = { |
| 17263 | MockWrite("POST / HTTP/1.1\r\n" |
| 17264 | "Host: www.foo.com\r\n" |
| 17265 | "Connection: keep-alive\r\n" |
| 17266 | "Content-Length: 3\r\n\r\n" |
| 17267 | "fo"), |
| 17268 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17269 | }; |
| 17270 | |
| 17271 | MockRead data_reads[] = { |
| 17272 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17273 | MockRead("hello world"), |
| 17274 | MockRead(SYNCHRONOUS, OK), |
| 17275 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17276 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17277 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17278 | |
| 17279 | TestCompletionCallback callback; |
| 17280 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17281 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17282 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17283 | |
| 17284 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17285 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17286 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17287 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17288 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17289 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17290 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17291 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17292 | |
| 17293 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17294 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17295 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17296 | EXPECT_EQ("hello world", response_data); |
| 17297 | } |
| 17298 | |
| 17299 | // This tests the more common case than the previous test, where headers and |
| 17300 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17301 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17302 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17303 | |
| 17304 | HttpRequestInfo request; |
| 17305 | request.method = "POST"; |
| 17306 | request.url = GURL("http://www.foo.com/"); |
| 17307 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17308 | request.traffic_annotation = |
| 17309 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17310 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17311 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17312 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17313 | // Send headers successfully, but get an error while sending the body. |
| 17314 | MockWrite data_writes[] = { |
| 17315 | MockWrite("POST / HTTP/1.1\r\n" |
| 17316 | "Host: www.foo.com\r\n" |
| 17317 | "Connection: keep-alive\r\n" |
| 17318 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17319 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17320 | }; |
| 17321 | |
| 17322 | MockRead data_reads[] = { |
| 17323 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17324 | MockRead("hello world"), |
| 17325 | MockRead(SYNCHRONOUS, OK), |
| 17326 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17327 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17328 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17329 | |
| 17330 | TestCompletionCallback callback; |
| 17331 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17332 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17333 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17334 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 17335 | // they can't be merged with the body in a single send. Not currently |
| 17336 | // necessary since a chunked body is never merged with headers, but this makes |
| 17337 | // the test more future proof. |
| 17338 | base::RunLoop().RunUntilIdle(); |
| 17339 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 17340 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17341 | |
| 17342 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17343 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17344 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17345 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17346 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17347 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17348 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17349 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17350 | |
| 17351 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17352 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17353 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17354 | EXPECT_EQ("hello world", response_data); |
| 17355 | } |
| 17356 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17357 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17358 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17359 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17360 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17361 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17362 | |
| 17363 | HttpRequestInfo request; |
| 17364 | request.method = "POST"; |
| 17365 | request.url = GURL("http://www.foo.com/"); |
| 17366 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17367 | request.traffic_annotation = |
| 17368 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17369 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17370 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17371 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17372 | |
| 17373 | MockWrite data_writes[] = { |
| 17374 | MockWrite("POST / HTTP/1.1\r\n" |
| 17375 | "Host: www.foo.com\r\n" |
| 17376 | "Connection: keep-alive\r\n" |
| 17377 | "Content-Length: 3\r\n\r\n"), |
| 17378 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17379 | }; |
| 17380 | |
| 17381 | MockRead data_reads[] = { |
| 17382 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17383 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 17384 | MockRead("hello world"), |
| 17385 | MockRead(SYNCHRONOUS, OK), |
| 17386 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17387 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17388 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17389 | |
| 17390 | TestCompletionCallback callback; |
| 17391 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17392 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17393 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17394 | |
| 17395 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17396 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17397 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17398 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17399 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17400 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17401 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17402 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 17403 | |
| 17404 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17405 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17406 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17407 | EXPECT_EQ("hello world", response_data); |
| 17408 | } |
| 17409 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17410 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17411 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17412 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17413 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17414 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17415 | |
| 17416 | HttpRequestInfo request; |
| 17417 | request.method = "POST"; |
| 17418 | request.url = GURL("http://www.foo.com/"); |
| 17419 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17420 | request.traffic_annotation = |
| 17421 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17422 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17423 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17424 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17425 | // Send headers successfully, but get an error while sending the body. |
| 17426 | MockWrite data_writes[] = { |
| 17427 | MockWrite("POST / HTTP/1.1\r\n" |
| 17428 | "Host: www.foo.com\r\n" |
| 17429 | "Connection: keep-alive\r\n" |
| 17430 | "Content-Length: 3\r\n\r\n"), |
| 17431 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17432 | }; |
| 17433 | |
| 17434 | MockRead data_reads[] = { |
| 17435 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 17436 | MockRead("hello world"), |
| 17437 | MockRead(SYNCHRONOUS, OK), |
| 17438 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17439 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17440 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17441 | |
| 17442 | TestCompletionCallback callback; |
| 17443 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17444 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17445 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17446 | |
| 17447 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17448 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17449 | } |
| 17450 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17451 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17452 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17453 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17454 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17455 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17456 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17457 | |
| 17458 | HttpRequestInfo request; |
| 17459 | request.method = "POST"; |
| 17460 | request.url = GURL("http://www.foo.com/"); |
| 17461 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17462 | request.traffic_annotation = |
| 17463 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17464 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17465 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17466 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17467 | // Send headers successfully, but get an error while sending the body. |
| 17468 | MockWrite data_writes[] = { |
| 17469 | MockWrite("POST / HTTP/1.1\r\n" |
| 17470 | "Host: www.foo.com\r\n" |
| 17471 | "Connection: keep-alive\r\n" |
| 17472 | "Content-Length: 3\r\n\r\n"), |
| 17473 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17474 | }; |
| 17475 | |
| 17476 | MockRead data_reads[] = { |
| 17477 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 17478 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 17479 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 17480 | MockRead("Content-Length: 0\r\n\r\n"), |
| 17481 | MockRead(SYNCHRONOUS, OK), |
| 17482 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17483 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17484 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17485 | |
| 17486 | TestCompletionCallback callback; |
| 17487 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17488 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17489 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17490 | |
| 17491 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17492 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17493 | } |
| 17494 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17495 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17496 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17497 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17498 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17499 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17500 | |
| 17501 | HttpRequestInfo request; |
| 17502 | request.method = "POST"; |
| 17503 | request.url = GURL("http://www.foo.com/"); |
| 17504 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17505 | request.traffic_annotation = |
| 17506 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17507 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17508 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17509 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17510 | // Send headers successfully, but get an error while sending the body. |
| 17511 | MockWrite data_writes[] = { |
| 17512 | MockWrite("POST / HTTP/1.1\r\n" |
| 17513 | "Host: www.foo.com\r\n" |
| 17514 | "Connection: keep-alive\r\n" |
| 17515 | "Content-Length: 3\r\n\r\n"), |
| 17516 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17517 | }; |
| 17518 | |
| 17519 | MockRead data_reads[] = { |
| 17520 | MockRead("HTTP 0.9 rocks!"), |
| 17521 | MockRead(SYNCHRONOUS, OK), |
| 17522 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17523 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17524 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17525 | |
| 17526 | TestCompletionCallback callback; |
| 17527 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17528 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17529 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17530 | |
| 17531 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17532 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17533 | } |
| 17534 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17535 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17536 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17537 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17538 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17539 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17540 | |
| 17541 | HttpRequestInfo request; |
| 17542 | request.method = "POST"; |
| 17543 | request.url = GURL("http://www.foo.com/"); |
| 17544 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17545 | request.traffic_annotation = |
| 17546 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17547 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17548 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17549 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17550 | // Send headers successfully, but get an error while sending the body. |
| 17551 | MockWrite data_writes[] = { |
| 17552 | MockWrite("POST / HTTP/1.1\r\n" |
| 17553 | "Host: www.foo.com\r\n" |
| 17554 | "Connection: keep-alive\r\n" |
| 17555 | "Content-Length: 3\r\n\r\n"), |
| 17556 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 17557 | }; |
| 17558 | |
| 17559 | MockRead data_reads[] = { |
| 17560 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 17561 | MockRead(SYNCHRONOUS, OK), |
| 17562 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17563 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17564 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17565 | |
| 17566 | TestCompletionCallback callback; |
| 17567 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17568 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17569 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17570 | |
| 17571 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17572 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 17573 | } |
| 17574 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17575 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17576 | |
| 17577 | namespace { |
| 17578 | |
| 17579 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
| 17580 | headers->SetHeader("Connection", "Upgrade"); |
| 17581 | headers->SetHeader("Upgrade", "websocket"); |
| 17582 | headers->SetHeader("Origin", "http://www.example.org"); |
| 17583 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17584 | } |
| 17585 | |
| 17586 | } // namespace |
| 17587 | |
| 17588 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17589 | for (bool secure : {true, false}) { |
| 17590 | MockWrite data_writes[] = { |
| 17591 | MockWrite("GET / HTTP/1.1\r\n" |
| 17592 | "Host: www.example.org\r\n" |
| 17593 | "Connection: Upgrade\r\n" |
| 17594 | "Upgrade: websocket\r\n" |
| 17595 | "Origin: http://www.example.org\r\n" |
| 17596 | "Sec-WebSocket-Version: 13\r\n" |
| 17597 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17598 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17599 | "client_max_window_bits\r\n\r\n")}; |
| 17600 | |
| 17601 | MockRead data_reads[] = { |
| 17602 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17603 | "Upgrade: websocket\r\n" |
| 17604 | "Connection: Upgrade\r\n" |
| 17605 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
| 17606 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17607 | StaticSocketDataProvider data(data_reads, data_writes); |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17608 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17609 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17610 | if (secure) |
| 17611 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17612 | |
| 17613 | HttpRequestInfo request; |
| 17614 | request.method = "GET"; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17615 | request.url = |
| 17616 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 17617 | AddWebSocketHeaders(&request.extra_headers); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17618 | request.traffic_annotation = |
| 17619 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17620 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17621 | TestWebSocketHandshakeStreamCreateHelper |
| 17622 | websocket_handshake_stream_create_helper; |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17623 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17624 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17625 | HttpNetworkTransaction trans(LOW, session.get()); |
| 17626 | trans.SetWebSocketHandshakeStreamCreateHelper( |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17627 | &websocket_handshake_stream_create_helper); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17628 | |
| 17629 | TestCompletionCallback callback; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17630 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17631 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17632 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 17633 | const HttpStreamRequest* stream_request = trans.stream_request_.get(); |
| 17634 | ASSERT_TRUE(stream_request); |
| 17635 | EXPECT_EQ(&websocket_handshake_stream_create_helper, |
| 17636 | stream_request->websocket_handshake_stream_create_helper()); |
| 17637 | |
| 17638 | rv = callback.WaitForResult(); |
| 17639 | EXPECT_THAT(rv, IsOk()); |
| 17640 | |
| 17641 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 17642 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17643 | } |
| 17644 | } |
| 17645 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17646 | // Verify that proxy headers are not sent to the destination server when |
| 17647 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17648 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17649 | HttpRequestInfo request; |
| 17650 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17651 | request.url = GURL("wss://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17652 | request.traffic_annotation = |
| 17653 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17654 | AddWebSocketHeaders(&request.extra_headers); |
| 17655 | |
| 17656 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17657 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17658 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17659 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17660 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17661 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17662 | |
| 17663 | // Since a proxy is configured, try to establish a tunnel. |
| 17664 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17665 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17666 | "Host: www.example.org:443\r\n" |
| 17667 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17668 | |
| 17669 | // After calling trans->RestartWithAuth(), this is the request we should |
| 17670 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17671 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 17672 | "Host: www.example.org:443\r\n" |
| 17673 | "Proxy-Connection: keep-alive\r\n" |
| 17674 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17675 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 17676 | MockWrite("GET / HTTP/1.1\r\n" |
| 17677 | "Host: www.example.org\r\n" |
| 17678 | "Connection: Upgrade\r\n" |
| 17679 | "Upgrade: websocket\r\n" |
| 17680 | "Origin: http://www.example.org\r\n" |
| 17681 | "Sec-WebSocket-Version: 13\r\n" |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17682 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17683 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17684 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17685 | |
| 17686 | // The proxy responds to the connect with a 407, using a persistent |
| 17687 | // connection. |
| 17688 | MockRead data_reads[] = { |
| 17689 | // No credentials. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17690 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 17691 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 17692 | "Content-Length: 0\r\n" |
| 17693 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17694 | |
| 17695 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17696 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17697 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17698 | "Upgrade: websocket\r\n" |
| 17699 | "Connection: Upgrade\r\n" |
| 17700 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17701 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17702 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17703 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17704 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17705 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17706 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17707 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17708 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17709 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17710 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17711 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17712 | &websocket_stream_create_helper); |
| 17713 | |
| 17714 | { |
| 17715 | TestCompletionCallback callback; |
| 17716 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17717 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17718 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17719 | |
| 17720 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17721 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17722 | } |
| 17723 | |
| 17724 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17725 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17726 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17727 | EXPECT_EQ(407, response->headers->response_code()); |
| 17728 | |
| 17729 | { |
| 17730 | TestCompletionCallback callback; |
| 17731 | |
| 17732 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 17733 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17734 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17735 | |
| 17736 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17737 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17738 | } |
| 17739 | |
| 17740 | response = trans->GetResponseInfo(); |
| 17741 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17742 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17743 | |
| 17744 | EXPECT_EQ(101, response->headers->response_code()); |
| 17745 | |
| 17746 | trans.reset(); |
| 17747 | session->CloseAllConnections(); |
| 17748 | } |
| 17749 | |
| 17750 | // Verify that proxy headers are not sent to the destination server when |
| 17751 | // establishing a tunnel for an insecure WebSocket connection. |
| 17752 | // This requires the authentication info to be injected into the auth cache |
| 17753 | // due to crbug.com/395064 |
| 17754 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17755 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17756 | HttpRequestInfo request; |
| 17757 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 17758 | request.url = GURL("ws://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17759 | request.traffic_annotation = |
| 17760 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17761 | AddWebSocketHeaders(&request.extra_headers); |
| 17762 | |
| 17763 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17764 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17765 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17766 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17767 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17768 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17769 | |
| 17770 | MockWrite data_writes[] = { |
| 17771 | // Try to establish a tunnel for the WebSocket connection, with |
| 17772 | // credentials. Because WebSockets have a separate set of socket pools, |
| 17773 | // they cannot and will not use the same TCP/IP connection as the |
| 17774 | // preflight HTTP request. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17775 | MockWrite("CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 17776 | "Host: www.example.org:80\r\n" |
| 17777 | "Proxy-Connection: keep-alive\r\n" |
| 17778 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17779 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17780 | MockWrite("GET / HTTP/1.1\r\n" |
| 17781 | "Host: www.example.org\r\n" |
| 17782 | "Connection: Upgrade\r\n" |
| 17783 | "Upgrade: websocket\r\n" |
| 17784 | "Origin: http://www.example.org\r\n" |
| 17785 | "Sec-WebSocket-Version: 13\r\n" |
| 17786 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 17787 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17788 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17789 | |
| 17790 | MockRead data_reads[] = { |
| 17791 | // HTTP CONNECT with credentials. |
| 17792 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17793 | |
| 17794 | // WebSocket connection established inside tunnel. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17795 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17796 | "Upgrade: websocket\r\n" |
| 17797 | "Connection: Upgrade\r\n" |
| 17798 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17799 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17800 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17801 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17802 | |
| 17803 | session->http_auth_cache()->Add( |
| 17804 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 17805 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 17806 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17807 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17808 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17809 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17810 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17811 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17812 | &websocket_stream_create_helper); |
| 17813 | |
| 17814 | TestCompletionCallback callback; |
| 17815 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17816 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17817 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17818 | |
| 17819 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17820 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17821 | |
| 17822 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17823 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17824 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17825 | |
| 17826 | EXPECT_EQ(101, response->headers->response_code()); |
| 17827 | |
| 17828 | trans.reset(); |
| 17829 | session->CloseAllConnections(); |
| 17830 | } |
| 17831 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17832 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17833 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17834 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17835 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17836 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17837 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17838 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17839 | |
| 17840 | HttpRequestInfo request; |
| 17841 | request.method = "POST"; |
| 17842 | request.url = GURL("http://www.foo.com/"); |
| 17843 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17844 | request.traffic_annotation = |
| 17845 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17846 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17847 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17848 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17849 | MockWrite data_writes[] = { |
| 17850 | MockWrite("POST / HTTP/1.1\r\n" |
| 17851 | "Host: www.foo.com\r\n" |
| 17852 | "Connection: keep-alive\r\n" |
| 17853 | "Content-Length: 3\r\n\r\n"), |
| 17854 | MockWrite("foo"), |
| 17855 | }; |
| 17856 | |
| 17857 | MockRead data_reads[] = { |
| 17858 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17859 | MockRead(SYNCHRONOUS, OK), |
| 17860 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17861 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17862 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17863 | |
| 17864 | TestCompletionCallback callback; |
| 17865 | |
| 17866 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17867 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17868 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17869 | |
| 17870 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17871 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17872 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17873 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 17874 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17875 | } |
| 17876 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17877 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17878 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17879 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17880 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17881 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17882 | |
| 17883 | HttpRequestInfo request; |
| 17884 | request.method = "POST"; |
| 17885 | request.url = GURL("http://www.foo.com/"); |
| 17886 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17887 | request.traffic_annotation = |
| 17888 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17889 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17890 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17891 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17892 | MockWrite data_writes[] = { |
| 17893 | MockWrite("POST / HTTP/1.1\r\n" |
| 17894 | "Host: www.foo.com\r\n" |
| 17895 | "Connection: keep-alive\r\n" |
| 17896 | "Content-Length: 3\r\n\r\n"), |
| 17897 | MockWrite("foo"), |
| 17898 | }; |
| 17899 | |
| 17900 | MockRead data_reads[] = { |
| 17901 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 17902 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17903 | MockRead(SYNCHRONOUS, OK), |
| 17904 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17905 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17906 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17907 | |
| 17908 | TestCompletionCallback callback; |
| 17909 | |
| 17910 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17911 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17912 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17913 | |
| 17914 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17915 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17916 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17917 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 17918 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17919 | } |
| 17920 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17921 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17922 | ChunkedUploadDataStream upload_data_stream(0); |
| 17923 | |
| 17924 | HttpRequestInfo request; |
| 17925 | request.method = "POST"; |
| 17926 | request.url = GURL("http://www.foo.com/"); |
| 17927 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17928 | request.traffic_annotation = |
| 17929 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17930 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17931 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17932 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17933 | // Send headers successfully, but get an error while sending the body. |
| 17934 | MockWrite data_writes[] = { |
| 17935 | MockWrite("POST / HTTP/1.1\r\n" |
| 17936 | "Host: www.foo.com\r\n" |
| 17937 | "Connection: keep-alive\r\n" |
| 17938 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17939 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 17940 | }; |
| 17941 | |
| 17942 | MockRead data_reads[] = { |
| 17943 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17944 | MockRead(SYNCHRONOUS, OK), |
| 17945 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17946 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17947 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17948 | |
| 17949 | TestCompletionCallback callback; |
| 17950 | |
| 17951 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17952 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17953 | |
| 17954 | base::RunLoop().RunUntilIdle(); |
| 17955 | upload_data_stream.AppendData("f", 1, false); |
| 17956 | |
| 17957 | base::RunLoop().RunUntilIdle(); |
| 17958 | upload_data_stream.AppendData("oo", 2, true); |
| 17959 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17960 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17961 | |
| 17962 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17963 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17964 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17965 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 17966 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17967 | } |
| 17968 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17969 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 17970 | const std::string& accept_encoding, |
| 17971 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17972 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17973 | bool should_match) { |
| 17974 | HttpRequestInfo request; |
| 17975 | request.method = "GET"; |
| 17976 | request.url = GURL("http://www.foo.com/"); |
| 17977 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 17978 | accept_encoding); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17979 | request.traffic_annotation = |
| 17980 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17981 | |
| 17982 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 17983 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17984 | // Send headers successfully, but get an error while sending the body. |
| 17985 | MockWrite data_writes[] = { |
| 17986 | MockWrite("GET / HTTP/1.1\r\n" |
| 17987 | "Host: www.foo.com\r\n" |
| 17988 | "Connection: keep-alive\r\n" |
| 17989 | "Accept-Encoding: "), |
| 17990 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 17991 | }; |
| 17992 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17993 | std::string response_code = "200 OK"; |
| 17994 | std::string extra; |
| 17995 | if (!location.empty()) { |
| 17996 | response_code = "301 Redirect\r\nLocation: "; |
| 17997 | response_code.append(location); |
| 17998 | } |
| 17999 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18000 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18001 | MockRead("HTTP/1.0 "), |
| 18002 | MockRead(response_code.data()), |
| 18003 | MockRead("\r\nContent-Encoding: "), |
| 18004 | MockRead(content_encoding.data()), |
| 18005 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18006 | MockRead(SYNCHRONOUS, OK), |
| 18007 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 18008 | StaticSocketDataProvider data(data_reads, data_writes); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18009 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 18010 | |
| 18011 | TestCompletionCallback callback; |
| 18012 | |
| 18013 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18014 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18015 | |
| 18016 | rv = callback.WaitForResult(); |
| 18017 | if (should_match) { |
| 18018 | EXPECT_THAT(rv, IsOk()); |
| 18019 | } else { |
| 18020 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 18021 | } |
| 18022 | } |
| 18023 | |
| 18024 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18025 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18026 | } |
| 18027 | |
| 18028 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18029 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 18030 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18031 | } |
| 18032 | |
| 18033 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 18034 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 18035 | "", false); |
| 18036 | } |
| 18037 | |
| 18038 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 18039 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 18040 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 18041 | } |
| 18042 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18043 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 18044 | ProxyConfig proxy_config; |
| 18045 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18046 | proxy_config.set_pac_mandatory(true); |
| 18047 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18048 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18049 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18050 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 18051 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18052 | |
| 18053 | HttpRequestInfo request; |
| 18054 | request.method = "GET"; |
| 18055 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18056 | request.traffic_annotation = |
| 18057 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18058 | |
| 18059 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18060 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18061 | |
| 18062 | TestCompletionCallback callback; |
| 18063 | |
| 18064 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18065 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18066 | EXPECT_THAT(callback.WaitForResult(), |
| 18067 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18068 | } |
| 18069 | |
| 18070 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 18071 | ProxyConfig proxy_config; |
| 18072 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 18073 | proxy_config.set_pac_mandatory(true); |
| 18074 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 18075 | new MockAsyncProxyResolverFactory(false); |
| 18076 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18077 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18078 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 18079 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18080 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18081 | HttpRequestInfo request; |
| 18082 | request.method = "GET"; |
| 18083 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18084 | request.traffic_annotation = |
| 18085 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18086 | |
| 18087 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18088 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18089 | |
| 18090 | TestCompletionCallback callback; |
| 18091 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18092 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18093 | |
| 18094 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 18095 | ERR_FAILED, &resolver); |
| 18096 | EXPECT_THAT(callback.WaitForResult(), |
| 18097 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 18098 | } |
| 18099 | |
| 18100 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 18101 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 18102 | ProxyResolutionService::CreateFixedFromPacResult( |
| 18103 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18104 | session_deps_.enable_quic = false; |
| 18105 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18106 | |
| 18107 | HttpRequestInfo request; |
| 18108 | request.method = "GET"; |
| 18109 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 18110 | request.traffic_annotation = |
| 18111 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 18112 | |
| 18113 | TestCompletionCallback callback; |
| 18114 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18115 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 18116 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 18117 | |
| 18118 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 18119 | } |
| 18120 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18121 | //----------------------------------------------------------------------------- |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18122 | // Reporting tests |
| 18123 | |
| 18124 | #if BUILDFLAG(ENABLE_REPORTING) |
| 18125 | class HttpNetworkTransactionReportingTest : public HttpNetworkTransactionTest { |
| 18126 | protected: |
| 18127 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18128 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18129 | auto test_reporting_context = std::make_unique<TestReportingContext>( |
| 18130 | &clock_, &tick_clock_, ReportingPolicy()); |
| 18131 | test_reporting_context_ = test_reporting_context.get(); |
| 18132 | session_deps_.reporting_service = |
| 18133 | ReportingService::CreateForTesting(std::move(test_reporting_context)); |
| 18134 | } |
| 18135 | |
| 18136 | TestReportingContext* reporting_context() const { |
| 18137 | return test_reporting_context_; |
| 18138 | } |
| 18139 | |
| 18140 | void clear_reporting_service() { |
| 18141 | session_deps_.reporting_service.reset(); |
| 18142 | test_reporting_context_ = nullptr; |
| 18143 | } |
| 18144 | |
| 18145 | // Makes an HTTPS request that should install a valid Reporting policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18146 | void RequestPolicy(CertStatus cert_status = 0) { |
| 18147 | HttpRequestInfo request; |
| 18148 | request.method = "GET"; |
| 18149 | request.url = GURL(url_); |
| 18150 | request.traffic_annotation = |
| 18151 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18152 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18153 | MockRead data_reads[] = { |
| 18154 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18155 | MockRead("Report-To: {\"group\": \"nel\", \"max_age\": 86400, " |
| 18156 | "\"endpoints\": [{\"url\": " |
| 18157 | "\"https://www.example.org/upload/\"}]}\r\n"), |
| 18158 | MockRead("\r\n"), |
| 18159 | MockRead("hello world"), |
| 18160 | MockRead(SYNCHRONOUS, OK), |
| 18161 | }; |
| 18162 | MockWrite data_writes[] = { |
| 18163 | MockWrite("GET / HTTP/1.1\r\n" |
| 18164 | "Host: www.example.org\r\n" |
| 18165 | "Connection: keep-alive\r\n\r\n"), |
| 18166 | }; |
| 18167 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18168 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18169 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18170 | |
| 18171 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18172 | if (request.url.SchemeIsCryptographic()) { |
| 18173 | ssl.ssl_info.cert = |
| 18174 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18175 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18176 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18177 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18178 | } |
| 18179 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18180 | TestCompletionCallback callback; |
| 18181 | auto session = CreateSession(&session_deps_); |
| 18182 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 18183 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18184 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18185 | } |
| 18186 | |
| 18187 | protected: |
| 18188 | std::string url_ = "https://www.example.org/"; |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18189 | |
| 18190 | private: |
| 18191 | TestReportingContext* test_reporting_context_; |
| 18192 | }; |
| 18193 | |
| 18194 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18195 | DontProcessReportToHeaderNoService) { |
| 18196 | base::HistogramTester histograms; |
| 18197 | clear_reporting_service(); |
| 18198 | RequestPolicy(); |
| 18199 | histograms.ExpectBucketCount( |
| 18200 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18201 | ReportingHeaderParser::HeaderOutcome::DISCARDED_NO_REPORTING_SERVICE, 1); |
| 18202 | } |
| 18203 | |
| 18204 | TEST_F(HttpNetworkTransactionReportingTest, DontProcessReportToHeaderHttp) { |
| 18205 | base::HistogramTester histograms; |
| 18206 | url_ = "http://www.example.org/"; |
| 18207 | RequestPolicy(); |
| 18208 | histograms.ExpectBucketCount( |
| 18209 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18210 | ReportingHeaderParser::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18211 | } |
| 18212 | |
| 18213 | TEST_F(HttpNetworkTransactionReportingTest, ProcessReportToHeaderHttps) { |
| 18214 | RequestPolicy(); |
| 18215 | std::vector<const ReportingClient*> clients; |
| 18216 | reporting_context()->cache()->GetClients(&clients); |
| 18217 | ASSERT_EQ(1u, clients.size()); |
| 18218 | const auto* client = clients[0]; |
| 18219 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 18220 | client->origin); |
| 18221 | EXPECT_EQ(GURL("https://www.example.org/upload/"), client->endpoint); |
| 18222 | EXPECT_EQ("nel", client->group); |
| 18223 | } |
| 18224 | |
| 18225 | TEST_F(HttpNetworkTransactionReportingTest, |
| 18226 | DontProcessReportToHeaderInvalidHttps) { |
| 18227 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18228 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18229 | RequestPolicy(cert_status); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 18230 | histograms.ExpectBucketCount( |
| 18231 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 18232 | ReportingHeaderParser::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, 1); |
| 18233 | } |
| 18234 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 18235 | |
| 18236 | //----------------------------------------------------------------------------- |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18237 | // Network Error Logging tests |
| 18238 | |
| 18239 | #if BUILDFLAG(ENABLE_REPORTING) |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18240 | namespace { |
| 18241 | |
| 18242 | const char kUserAgent[] = "Mozilla/1.0"; |
| 18243 | const char kReferrer[] = "https://www.referrer.org/"; |
| 18244 | |
| 18245 | } // namespace |
| 18246 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18247 | class HttpNetworkTransactionNetworkErrorLoggingTest |
| 18248 | : public HttpNetworkTransactionTest { |
| 18249 | protected: |
| 18250 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18251 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18252 | auto network_error_logging_service = |
| 18253 | std::make_unique<TestNetworkErrorLoggingService>(); |
| 18254 | test_network_error_logging_service_ = network_error_logging_service.get(); |
| 18255 | session_deps_.network_error_logging_service = |
| 18256 | std::move(network_error_logging_service); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18257 | |
| 18258 | extra_headers_.SetHeader("User-Agent", kUserAgent); |
| 18259 | extra_headers_.SetHeader("Referer", kReferrer); |
| 18260 | |
| 18261 | request_.method = "GET"; |
| 18262 | request_.url = GURL(url_); |
| 18263 | request_.extra_headers = extra_headers_; |
| 18264 | request_.reporting_upload_depth = reporting_upload_depth_; |
| 18265 | request_.traffic_annotation = |
| 18266 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18267 | } |
| 18268 | |
| 18269 | TestNetworkErrorLoggingService* network_error_logging_service() const { |
| 18270 | return test_network_error_logging_service_; |
| 18271 | } |
| 18272 | |
| 18273 | void clear_network_error_logging_service() { |
| 18274 | session_deps_.network_error_logging_service.reset(); |
| 18275 | test_network_error_logging_service_ = nullptr; |
| 18276 | } |
| 18277 | |
| 18278 | // Makes an HTTPS request that should install a valid NEL policy. |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18279 | void RequestPolicy(CertStatus cert_status = 0) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18280 | std::string extra_header_string = extra_headers_.ToString(); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18281 | MockRead data_reads[] = { |
| 18282 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18283 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 18284 | MockRead("\r\n"), |
| 18285 | MockRead("hello world"), |
| 18286 | MockRead(SYNCHRONOUS, OK), |
| 18287 | }; |
| 18288 | MockWrite data_writes[] = { |
| 18289 | MockWrite("GET / HTTP/1.1\r\n" |
| 18290 | "Host: www.example.org\r\n" |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18291 | "Connection: keep-alive\r\n"), |
| 18292 | MockWrite(ASYNC, extra_header_string.data(), |
| 18293 | extra_header_string.size()), |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18294 | }; |
| 18295 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18296 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18297 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18298 | |
| 18299 | SSLSocketDataProvider ssl(ASYNC, OK); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18300 | if (request_.url.SchemeIsCryptographic()) { |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18301 | ssl.ssl_info.cert = |
| 18302 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 18303 | ASSERT_TRUE(ssl.ssl_info.cert); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18304 | ssl.ssl_info.cert_status = cert_status; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18305 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18306 | } |
| 18307 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18308 | TestCompletionCallback callback; |
| 18309 | auto session = CreateSession(&session_deps_); |
| 18310 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18311 | int rv = trans.Start(&request_, callback.callback(), NetLogWithSource()); |
| 18312 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18313 | |
| 18314 | std::string response_data; |
| 18315 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 18316 | EXPECT_EQ("hello world", response_data); |
| 18317 | } |
| 18318 | |
| 18319 | void CheckReport(size_t index, |
| 18320 | int status_code, |
| 18321 | int error_type, |
| 18322 | IPAddress server_ip = IPAddress::IPv4Localhost()) { |
| 18323 | ASSERT_LT(index, network_error_logging_service()->errors().size()); |
| 18324 | |
| 18325 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18326 | network_error_logging_service()->errors()[index]; |
| 18327 | EXPECT_EQ(url_, error.uri); |
| 18328 | EXPECT_EQ(kReferrer, error.referrer); |
| 18329 | EXPECT_EQ(kUserAgent, error.user_agent); |
| 18330 | EXPECT_EQ(server_ip, error.server_ip); |
| 18331 | EXPECT_EQ("http/1.1", error.protocol); |
| 18332 | EXPECT_EQ("GET", error.method); |
| 18333 | EXPECT_EQ(status_code, error.status_code); |
| 18334 | EXPECT_EQ(error_type, error.type); |
| 18335 | EXPECT_EQ(0, error.reporting_upload_depth); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18336 | } |
| 18337 | |
| 18338 | protected: |
| 18339 | std::string url_ = "https://www.example.org/"; |
| 18340 | CertStatus cert_status_ = 0; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18341 | HttpRequestInfo request_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18342 | HttpRequestHeaders extra_headers_; |
| 18343 | int reporting_upload_depth_ = 0; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18344 | |
| 18345 | private: |
| 18346 | TestNetworkErrorLoggingService* test_network_error_logging_service_; |
| 18347 | }; |
| 18348 | |
| 18349 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18350 | DontProcessNelHeaderNoService) { |
| 18351 | base::HistogramTester histograms; |
| 18352 | clear_network_error_logging_service(); |
| 18353 | RequestPolicy(); |
| 18354 | histograms.ExpectBucketCount( |
| 18355 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18356 | NetworkErrorLoggingService::HeaderOutcome:: |
| 18357 | DISCARDED_NO_NETWORK_ERROR_LOGGING_SERVICE, |
| 18358 | 1); |
| 18359 | } |
| 18360 | |
| 18361 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18362 | DontProcessNelHeaderHttp) { |
| 18363 | base::HistogramTester histograms; |
| 18364 | url_ = "http://www.example.org/"; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18365 | request_.url = GURL(url_); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18366 | RequestPolicy(); |
| 18367 | histograms.ExpectBucketCount( |
| 18368 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18369 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 18370 | } |
| 18371 | |
| 18372 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ProcessNelHeaderHttps) { |
| 18373 | RequestPolicy(); |
| 18374 | ASSERT_EQ(1u, network_error_logging_service()->headers().size()); |
| 18375 | const auto& header = network_error_logging_service()->headers()[0]; |
| 18376 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 18377 | header.origin); |
| 18378 | EXPECT_EQ(IPAddress::IPv4Localhost(), header.received_ip_address); |
| 18379 | EXPECT_EQ("{\"report_to\": \"nel\", \"max_age\": 86400}", header.value); |
| 18380 | } |
| 18381 | |
| 18382 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18383 | DontProcessNelHeaderInvalidHttps) { |
| 18384 | base::HistogramTester histograms; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18385 | CertStatus cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
| 18386 | RequestPolicy(cert_status); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 18387 | histograms.ExpectBucketCount( |
| 18388 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 18389 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, |
| 18390 | 1); |
| 18391 | } |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18392 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18393 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, CreateReportSuccess) { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 18394 | RequestPolicy(); |
| 18395 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 18396 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 18397 | } |
| 18398 | |
| 18399 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18400 | CreateReportErrorAfterStart) { |
| 18401 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18402 | auto trans = |
| 18403 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18404 | |
| 18405 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
| 18406 | StaticSocketDataProvider data; |
| 18407 | data.set_connect_data(mock_connect); |
| 18408 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18409 | |
| 18410 | TestCompletionCallback callback; |
| 18411 | |
| 18412 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18413 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18414 | |
| 18415 | trans.reset(); |
| 18416 | |
| 18417 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18418 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18419 | IPAddress() /* server_ip */); |
| 18420 | } |
| 18421 | |
| 18422 | // Same as above except the error is ASYNC |
| 18423 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18424 | CreateReportErrorAfterStartAsync) { |
| 18425 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18426 | auto trans = |
| 18427 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18428 | |
| 18429 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
| 18430 | StaticSocketDataProvider data; |
| 18431 | data.set_connect_data(mock_connect); |
| 18432 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 18433 | |
| 18434 | TestCompletionCallback callback; |
| 18435 | |
| 18436 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18437 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_NAME_NOT_RESOLVED)); |
| 18438 | |
| 18439 | trans.reset(); |
| 18440 | |
| 18441 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18442 | CheckReport(0 /* index */, 0 /* status_code */, ERR_NAME_NOT_RESOLVED, |
| 18443 | IPAddress() /* server_ip */); |
| 18444 | } |
| 18445 | |
| 18446 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18447 | CreateReportReadBodyError) { |
| 18448 | std::string extra_header_string = extra_headers_.ToString(); |
| 18449 | MockRead data_reads[] = { |
| 18450 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18451 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18452 | MockRead("hello world"), |
| 18453 | MockRead(SYNCHRONOUS, OK), |
| 18454 | }; |
| 18455 | MockWrite data_writes[] = { |
| 18456 | MockWrite("GET / HTTP/1.1\r\n" |
| 18457 | "Host: www.example.org\r\n" |
| 18458 | "Connection: keep-alive\r\n"), |
| 18459 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18460 | }; |
| 18461 | |
| 18462 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18463 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18464 | |
| 18465 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18466 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18467 | |
| 18468 | // Log start time |
| 18469 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18470 | |
| 18471 | TestCompletionCallback callback; |
| 18472 | auto session = CreateSession(&session_deps_); |
| 18473 | auto trans = |
| 18474 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18475 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18476 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18477 | |
| 18478 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18479 | ASSERT_TRUE(response); |
| 18480 | |
| 18481 | EXPECT_TRUE(response->headers); |
| 18482 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 18483 | |
| 18484 | std::string response_data; |
| 18485 | rv = ReadTransaction(trans.get(), &response_data); |
| 18486 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 18487 | |
| 18488 | trans.reset(); |
| 18489 | |
| 18490 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18491 | |
| 18492 | CheckReport(0 /* index */, 200 /* status_code */, |
| 18493 | ERR_CONTENT_LENGTH_MISMATCH); |
| 18494 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18495 | network_error_logging_service()->errors()[0]; |
| 18496 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 18497 | } |
| 18498 | |
| 18499 | // Same as above except the final read is ASYNC. |
| 18500 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18501 | CreateReportReadBodyErrorAsync) { |
| 18502 | std::string extra_header_string = extra_headers_.ToString(); |
| 18503 | MockRead data_reads[] = { |
| 18504 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 18505 | MockRead("Content-Length: 100\r\n\r\n"), // wrong content length |
| 18506 | MockRead("hello world"), |
| 18507 | MockRead(ASYNC, OK), |
| 18508 | }; |
| 18509 | MockWrite data_writes[] = { |
| 18510 | MockWrite("GET / HTTP/1.1\r\n" |
| 18511 | "Host: www.example.org\r\n" |
| 18512 | "Connection: keep-alive\r\n"), |
| 18513 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18514 | }; |
| 18515 | |
| 18516 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 18517 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 18518 | |
| 18519 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 18520 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 18521 | |
| 18522 | // Log start time |
| 18523 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18524 | |
| 18525 | TestCompletionCallback callback; |
| 18526 | auto session = CreateSession(&session_deps_); |
| 18527 | auto trans = |
| 18528 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18529 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 18530 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18531 | |
| 18532 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 18533 | ASSERT_TRUE(response); |
| 18534 | |
| 18535 | EXPECT_TRUE(response->headers); |
| 18536 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 18537 | |
| 18538 | std::string response_data; |
| 18539 | rv = ReadTransaction(trans.get(), &response_data); |
| 18540 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
| 18541 | |
| 18542 | trans.reset(); |
| 18543 | |
| 18544 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18545 | |
| 18546 | CheckReport(0 /* index */, 200 /* status_code */, |
| 18547 | ERR_CONTENT_LENGTH_MISMATCH); |
| 18548 | const NetworkErrorLoggingService::RequestDetails& error = |
| 18549 | network_error_logging_service()->errors()[0]; |
| 18550 | EXPECT_LE(error.elapsed_time, base::TimeTicks::Now() - start_time); |
| 18551 | } |
| 18552 | |
| 18553 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18554 | CreateReportRestartWithAuth) { |
| 18555 | std::string extra_header_string = extra_headers_.ToString(); |
| 18556 | static const base::TimeDelta kSleepDuration = |
| 18557 | base::TimeDelta::FromMilliseconds(10); |
| 18558 | |
| 18559 | MockWrite data_writes1[] = { |
| 18560 | MockWrite("GET / HTTP/1.1\r\n" |
| 18561 | "Host: www.example.org\r\n" |
| 18562 | "Connection: keep-alive\r\n"), |
| 18563 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18564 | }; |
| 18565 | |
| 18566 | MockRead data_reads1[] = { |
| 18567 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 18568 | // Give a couple authenticate options (only the middle one is actually |
| 18569 | // supported). |
| 18570 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 18571 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 18572 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 18573 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18574 | // Large content-length -- won't matter, as connection will be reset. |
| 18575 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 18576 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 18577 | }; |
| 18578 | |
| 18579 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18580 | // be issuing -- the final header line contains the credentials. |
| 18581 | MockWrite data_writes2[] = { |
| 18582 | MockWrite("GET / HTTP/1.1\r\n" |
| 18583 | "Host: www.example.org\r\n" |
| 18584 | "Connection: keep-alive\r\n" |
| 18585 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 18586 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18587 | }; |
| 18588 | |
| 18589 | // Lastly, the server responds with the actual content. |
| 18590 | MockRead data_reads2[] = { |
| 18591 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 18592 | MockRead("hello world"), |
| 18593 | MockRead(SYNCHRONOUS, OK), |
| 18594 | }; |
| 18595 | |
| 18596 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18597 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 18598 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18599 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18600 | |
| 18601 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18602 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18603 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18604 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18605 | |
| 18606 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18607 | base::TimeTicks restart_time; |
| 18608 | |
| 18609 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18610 | auto trans = |
| 18611 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18612 | |
| 18613 | TestCompletionCallback callback1; |
| 18614 | |
| 18615 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18616 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18617 | |
| 18618 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18619 | |
| 18620 | TestCompletionCallback callback2; |
| 18621 | |
| 18622 | // Wait 10 ms then restart with auth |
| 18623 | FastForwardBy(kSleepDuration); |
| 18624 | restart_time = base::TimeTicks::Now(); |
| 18625 | rv = |
| 18626 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 18627 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18628 | |
| 18629 | std::string response_data; |
| 18630 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 18631 | EXPECT_EQ("hello world", response_data); |
| 18632 | |
| 18633 | trans.reset(); |
| 18634 | |
| 18635 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 18636 | // retry. Note that we don't report the error draining the body, as the first |
| 18637 | // request already generated a report for the auth challenge. |
| 18638 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 18639 | |
| 18640 | // Check error report contents |
| 18641 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 18642 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 18643 | |
| 18644 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 18645 | network_error_logging_service()->errors()[0]; |
| 18646 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 18647 | network_error_logging_service()->errors()[1]; |
| 18648 | |
| 18649 | // Sanity-check elapsed time values |
| 18650 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 18651 | // Check that the start time is refreshed when restarting with auth. |
| 18652 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 18653 | } |
| 18654 | |
| 18655 | // Same as above, except draining the body before restarting fails |
| 18656 | // asynchronously. |
| 18657 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18658 | CreateReportRestartWithAuthAsync) { |
| 18659 | std::string extra_header_string = extra_headers_.ToString(); |
| 18660 | static const base::TimeDelta kSleepDuration = |
| 18661 | base::TimeDelta::FromMilliseconds(10); |
| 18662 | |
| 18663 | MockWrite data_writes1[] = { |
| 18664 | MockWrite("GET / HTTP/1.1\r\n" |
| 18665 | "Host: www.example.org\r\n" |
| 18666 | "Connection: keep-alive\r\n"), |
| 18667 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18668 | }; |
| 18669 | |
| 18670 | MockRead data_reads1[] = { |
| 18671 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 18672 | // Give a couple authenticate options (only the middle one is actually |
| 18673 | // supported). |
| 18674 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 18675 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 18676 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 18677 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 18678 | // Large content-length -- won't matter, as connection will be reset. |
| 18679 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 18680 | MockRead(ASYNC, ERR_FAILED), |
| 18681 | }; |
| 18682 | |
| 18683 | // After calling trans->RestartWithAuth(), this is the request we should |
| 18684 | // be issuing -- the final header line contains the credentials. |
| 18685 | MockWrite data_writes2[] = { |
| 18686 | MockWrite("GET / HTTP/1.1\r\n" |
| 18687 | "Host: www.example.org\r\n" |
| 18688 | "Connection: keep-alive\r\n" |
| 18689 | "Authorization: Basic Zm9vOmJhcg==\r\n"), |
| 18690 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18691 | }; |
| 18692 | |
| 18693 | // Lastly, the server responds with the actual content. |
| 18694 | MockRead data_reads2[] = { |
| 18695 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 18696 | MockRead("hello world"), |
| 18697 | MockRead(SYNCHRONOUS, OK), |
| 18698 | }; |
| 18699 | |
| 18700 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18701 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 18702 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18703 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18704 | |
| 18705 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18706 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18707 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18708 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18709 | |
| 18710 | base::TimeTicks start_time = base::TimeTicks::Now(); |
| 18711 | base::TimeTicks restart_time; |
| 18712 | |
| 18713 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18714 | auto trans = |
| 18715 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18716 | |
| 18717 | TestCompletionCallback callback1; |
| 18718 | |
| 18719 | int rv = trans->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18720 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18721 | |
| 18722 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18723 | |
| 18724 | TestCompletionCallback callback2; |
| 18725 | |
| 18726 | // Wait 10 ms then restart with auth |
| 18727 | FastForwardBy(kSleepDuration); |
| 18728 | restart_time = base::TimeTicks::Now(); |
| 18729 | rv = |
| 18730 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
| 18731 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18732 | |
| 18733 | std::string response_data; |
| 18734 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 18735 | EXPECT_EQ("hello world", response_data); |
| 18736 | |
| 18737 | trans.reset(); |
| 18738 | |
| 18739 | // One 401 report for the auth challenge, then a 200 report for the successful |
| 18740 | // retry. Note that we don't report the error draining the body, as the first |
| 18741 | // request already generated a report for the auth challenge. |
| 18742 | ASSERT_EQ(2u, network_error_logging_service()->errors().size()); |
| 18743 | |
| 18744 | // Check error report contents |
| 18745 | CheckReport(0 /* index */, 401 /* status_code */, OK); |
| 18746 | CheckReport(1 /* index */, 200 /* status_code */, OK); |
| 18747 | |
| 18748 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 18749 | network_error_logging_service()->errors()[0]; |
| 18750 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 18751 | network_error_logging_service()->errors()[1]; |
| 18752 | |
| 18753 | // Sanity-check elapsed time values |
| 18754 | EXPECT_EQ(error1.elapsed_time, restart_time - start_time - kSleepDuration); |
| 18755 | // Check that the start time is refreshed when restarting with auth. |
| 18756 | EXPECT_EQ(error2.elapsed_time, base::TimeTicks::Now() - restart_time); |
| 18757 | } |
| 18758 | |
| 18759 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18760 | CreateReportRetryKeepAliveConnectionReset) { |
| 18761 | std::string extra_header_string = extra_headers_.ToString(); |
| 18762 | MockWrite data_writes1[] = { |
| 18763 | MockWrite("GET / HTTP/1.1\r\n" |
| 18764 | "Host: www.example.org\r\n" |
| 18765 | "Connection: keep-alive\r\n"), |
| 18766 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18767 | MockWrite("GET / HTTP/1.1\r\n" |
| 18768 | "Host: www.example.org\r\n" |
| 18769 | "Connection: keep-alive\r\n"), |
| 18770 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18771 | }; |
| 18772 | |
| 18773 | MockRead data_reads1[] = { |
| 18774 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 18775 | MockRead("hello"), |
| 18776 | // Connection is reset |
| 18777 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 18778 | }; |
| 18779 | |
| 18780 | // Successful retry |
| 18781 | MockRead data_reads2[] = { |
| 18782 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 18783 | MockRead("world"), |
| 18784 | MockRead(ASYNC, OK), |
| 18785 | }; |
| 18786 | |
| 18787 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18788 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 18789 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18790 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18791 | |
| 18792 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18793 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18794 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18795 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18796 | |
| 18797 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18798 | auto trans1 = |
| 18799 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18800 | |
| 18801 | TestCompletionCallback callback1; |
| 18802 | |
| 18803 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18804 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18805 | |
| 18806 | std::string response_data; |
| 18807 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 18808 | EXPECT_EQ("hello", response_data); |
| 18809 | |
| 18810 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18811 | |
| 18812 | auto trans2 = |
| 18813 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18814 | |
| 18815 | TestCompletionCallback callback2; |
| 18816 | |
| 18817 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 18818 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18819 | |
| 18820 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 18821 | EXPECT_EQ("world", response_data); |
| 18822 | |
| 18823 | trans1.reset(); |
| 18824 | trans2.reset(); |
| 18825 | |
| 18826 | // One OK report from first request, then a ERR_CONNECTION_RESET report from |
| 18827 | // the second request, then an OK report from the successful retry. |
| 18828 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 18829 | |
| 18830 | // Check error report contents |
| 18831 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 18832 | CheckReport(1 /* index */, 0 /* status_code */, ERR_CONNECTION_RESET); |
| 18833 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 18834 | } |
| 18835 | |
| 18836 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18837 | CreateReportRetryKeepAlive408) { |
| 18838 | std::string extra_header_string = extra_headers_.ToString(); |
| 18839 | MockWrite data_writes1[] = { |
| 18840 | MockWrite("GET / HTTP/1.1\r\n" |
| 18841 | "Host: www.example.org\r\n" |
| 18842 | "Connection: keep-alive\r\n"), |
| 18843 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18844 | MockWrite("GET / HTTP/1.1\r\n" |
| 18845 | "Host: www.example.org\r\n" |
| 18846 | "Connection: keep-alive\r\n"), |
| 18847 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 18848 | }; |
| 18849 | |
| 18850 | MockRead data_reads1[] = { |
| 18851 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 18852 | MockRead("hello"), |
| 18853 | // 408 Request Timeout |
| 18854 | MockRead(SYNCHRONOUS, |
| 18855 | "HTTP/1.1 408 Request Timeout\r\n" |
| 18856 | "Connection: Keep-Alive\r\n" |
| 18857 | "Content-Length: 6\r\n\r\n" |
| 18858 | "Pickle"), |
| 18859 | }; |
| 18860 | |
| 18861 | // Successful retry |
| 18862 | MockRead data_reads2[] = { |
| 18863 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 18864 | MockRead("world"), |
| 18865 | MockRead(ASYNC, OK), |
| 18866 | }; |
| 18867 | |
| 18868 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 18869 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
| 18870 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18871 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18872 | |
| 18873 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 18874 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 18875 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 18876 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 18877 | |
| 18878 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18879 | auto trans1 = |
| 18880 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18881 | |
| 18882 | TestCompletionCallback callback1; |
| 18883 | |
| 18884 | int rv = trans1->Start(&request_, callback1.callback(), NetLogWithSource()); |
| 18885 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
| 18886 | |
| 18887 | std::string response_data; |
| 18888 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 18889 | EXPECT_EQ("hello", response_data); |
| 18890 | |
| 18891 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 18892 | |
| 18893 | auto trans2 = |
| 18894 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 18895 | |
| 18896 | TestCompletionCallback callback2; |
| 18897 | |
| 18898 | rv = trans2->Start(&request_, callback2.callback(), NetLogWithSource()); |
| 18899 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
| 18900 | |
| 18901 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 18902 | EXPECT_EQ("world", response_data); |
| 18903 | |
| 18904 | trans1.reset(); |
| 18905 | trans2.reset(); |
| 18906 | |
| 18907 | // One 200 report from first request, then a 408 report from |
| 18908 | // the second request, then a 200 report from the successful retry. |
| 18909 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 18910 | |
| 18911 | // Check error report contents |
| 18912 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 18913 | CheckReport(1 /* index */, 408 /* status_code */, OK); |
| 18914 | CheckReport(2 /* index */, 200 /* status_code */, OK); |
| 18915 | } |
| 18916 | |
| 18917 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 18918 | CreateReportRetry421WithoutConnectionPooling) { |
| 18919 | // Two hosts resolve to the same IP address. |
| 18920 | const std::string ip_addr = "1.2.3.4"; |
| 18921 | IPAddress ip; |
| 18922 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 18923 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 18924 | |
| 18925 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
| 18926 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 18927 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 18928 | |
| 18929 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 18930 | |
| 18931 | // Two requests on the first connection. |
| 18932 | spdy::SpdySerializedFrame req1( |
| 18933 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 18934 | spdy_util_.UpdateWithStreamDestruction(1); |
| 18935 | spdy::SpdySerializedFrame req2( |
| 18936 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
| 18937 | spdy::SpdySerializedFrame rst( |
| 18938 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
| 18939 | MockWrite writes1[] = { |
| 18940 | CreateMockWrite(req1, 0), |
| 18941 | CreateMockWrite(req2, 3), |
| 18942 | CreateMockWrite(rst, 6), |
| 18943 | }; |
| 18944 | |
| 18945 | // The first one succeeds, the second gets error 421 Misdirected Request. |
| 18946 | spdy::SpdySerializedFrame resp1( |
| 18947 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 18948 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 18949 | spdy::SpdyHeaderBlock response_headers; |
| 18950 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 18951 | spdy::SpdySerializedFrame resp2( |
| 18952 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 18953 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 18954 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 18955 | |
| 18956 | MockConnect connect1(ASYNC, OK, peer_addr); |
| 18957 | SequencedSocketData data1(connect1, reads1, writes1); |
| 18958 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 18959 | |
| 18960 | AddSSLSocketData(); |
| 18961 | |
| 18962 | // Retry the second request on a second connection. |
| 18963 | SpdyTestUtil spdy_util2; |
| 18964 | spdy::SpdySerializedFrame req3( |
| 18965 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 18966 | MockWrite writes2[] = { |
| 18967 | CreateMockWrite(req3, 0), |
| 18968 | }; |
| 18969 | |
| 18970 | spdy::SpdySerializedFrame resp3( |
| 18971 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 18972 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
| 18973 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 18974 | MockRead(ASYNC, 0, 3)}; |
| 18975 | |
| 18976 | MockConnect connect2(ASYNC, OK, peer_addr); |
| 18977 | SequencedSocketData data2(connect2, reads2, writes2); |
| 18978 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 18979 | |
| 18980 | AddSSLSocketData(); |
| 18981 | |
| 18982 | // Preload mail.example.org into HostCache. |
| 18983 | HostPortPair host_port("mail.example.org", 443); |
| 18984 | HostResolver::RequestInfo resolve_info(host_port); |
| 18985 | AddressList ignored; |
| 18986 | std::unique_ptr<HostResolver::Request> request; |
| 18987 | TestCompletionCallback callback; |
| 18988 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 18989 | &ignored, callback.callback(), |
| 18990 | &request, NetLogWithSource()); |
| 18991 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 18992 | |
| 18993 | HttpRequestInfo request1; |
| 18994 | request1.method = "GET"; |
| 18995 | request1.url = GURL("https://www.example.org/"); |
| 18996 | request1.load_flags = 0; |
| 18997 | request1.traffic_annotation = |
| 18998 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 18999 | auto trans1 = |
| 19000 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19001 | |
| 19002 | rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
| 19003 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19004 | |
| 19005 | const HttpResponseInfo* response = trans1->GetResponseInfo(); |
| 19006 | ASSERT_TRUE(response); |
| 19007 | ASSERT_TRUE(response->headers); |
| 19008 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19009 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19010 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19011 | std::string response_data; |
| 19012 | ASSERT_THAT(ReadTransaction(trans1.get(), &response_data), IsOk()); |
| 19013 | EXPECT_EQ("hello!", response_data); |
| 19014 | |
| 19015 | trans1.reset(); |
| 19016 | |
| 19017 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19018 | |
| 19019 | HttpRequestInfo request2; |
| 19020 | request2.method = "GET"; |
| 19021 | request2.url = GURL("https://mail.example.org/"); |
| 19022 | request2.load_flags = 0; |
| 19023 | request2.traffic_annotation = |
| 19024 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 19025 | auto trans2 = |
| 19026 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19027 | |
| 19028 | BoundTestNetLog log; |
| 19029 | rv = trans2->Start(&request2, callback.callback(), log.bound()); |
| 19030 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19031 | |
| 19032 | response = trans2->GetResponseInfo(); |
| 19033 | ASSERT_TRUE(response); |
| 19034 | ASSERT_TRUE(response->headers); |
| 19035 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 19036 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 19037 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 19038 | ASSERT_THAT(ReadTransaction(trans2.get(), &response_data), IsOk()); |
| 19039 | EXPECT_EQ("hello!", response_data); |
| 19040 | |
| 19041 | trans2.reset(); |
| 19042 | |
| 19043 | // One 200 report from the first request, then a 421 report from the |
| 19044 | // second request, then a 200 report from the successful retry. |
| 19045 | ASSERT_EQ(3u, network_error_logging_service()->errors().size()); |
| 19046 | |
| 19047 | // Check error report contents |
| 19048 | const NetworkErrorLoggingService::RequestDetails& error1 = |
| 19049 | network_error_logging_service()->errors()[0]; |
| 19050 | EXPECT_EQ(GURL("https://www.example.org/"), error1.uri); |
| 19051 | EXPECT_TRUE(error1.referrer.is_empty()); |
| 19052 | EXPECT_EQ("", error1.user_agent); |
| 19053 | EXPECT_EQ(ip, error1.server_ip); |
| 19054 | EXPECT_EQ("h2", error1.protocol); |
| 19055 | EXPECT_EQ("GET", error1.method); |
| 19056 | EXPECT_EQ(200, error1.status_code); |
| 19057 | EXPECT_EQ(OK, error1.type); |
| 19058 | EXPECT_EQ(0, error1.reporting_upload_depth); |
| 19059 | |
| 19060 | const NetworkErrorLoggingService::RequestDetails& error2 = |
| 19061 | network_error_logging_service()->errors()[1]; |
| 19062 | EXPECT_EQ(GURL("https://mail.example.org/"), error2.uri); |
| 19063 | EXPECT_TRUE(error2.referrer.is_empty()); |
| 19064 | EXPECT_EQ("", error2.user_agent); |
| 19065 | EXPECT_EQ(ip, error2.server_ip); |
| 19066 | EXPECT_EQ("h2", error2.protocol); |
| 19067 | EXPECT_EQ("GET", error2.method); |
| 19068 | EXPECT_EQ(421, error2.status_code); |
| 19069 | EXPECT_EQ(OK, error2.type); |
| 19070 | EXPECT_EQ(0, error2.reporting_upload_depth); |
| 19071 | |
| 19072 | const NetworkErrorLoggingService::RequestDetails& error3 = |
| 19073 | network_error_logging_service()->errors()[2]; |
| 19074 | EXPECT_EQ(GURL("https://mail.example.org/"), error3.uri); |
| 19075 | EXPECT_TRUE(error3.referrer.is_empty()); |
| 19076 | EXPECT_EQ("", error3.user_agent); |
| 19077 | EXPECT_EQ(ip, error3.server_ip); |
| 19078 | EXPECT_EQ("h2", error3.protocol); |
| 19079 | EXPECT_EQ("GET", error3.method); |
| 19080 | EXPECT_EQ(200, error3.status_code); |
| 19081 | EXPECT_EQ(OK, error3.type); |
| 19082 | EXPECT_EQ(0, error3.reporting_upload_depth); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19083 | } |
| 19084 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19085 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, DontCreateReportHttp) { |
| 19086 | base::HistogramTester histograms; |
| 19087 | RequestPolicy(); |
| 19088 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19089 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19090 | |
| 19091 | // Make HTTP request |
| 19092 | std::string extra_header_string = extra_headers_.ToString(); |
| 19093 | MockRead data_reads[] = { |
| 19094 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 19095 | MockRead("hello world"), |
| 19096 | MockRead(SYNCHRONOUS, OK), |
| 19097 | }; |
| 19098 | MockWrite data_writes[] = { |
| 19099 | MockWrite("GET / HTTP/1.1\r\n" |
| 19100 | "Host: www.example.org\r\n" |
| 19101 | "Connection: keep-alive\r\n"), |
| 19102 | MockWrite(ASYNC, extra_header_string.data(), extra_header_string.size()), |
| 19103 | }; |
| 19104 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19105 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 19106 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 19107 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19108 | // Insecure url |
| 19109 | url_ = "http://www.example.org/"; |
| 19110 | request_.url = GURL(url_); |
| 19111 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19112 | TestCompletionCallback callback; |
| 19113 | auto session = CreateSession(&session_deps_); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19114 | auto trans = |
| 19115 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19116 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19117 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19118 | |
| 19119 | std::string response_data; |
| 19120 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19121 | EXPECT_EQ("hello world", response_data); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19122 | |
| 19123 | // Insecure request does not generate a report |
| 19124 | histograms.ExpectBucketCount( |
| 19125 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
| 19126 | NetworkErrorLoggingService::RequestOutcome::DISCARDED_INSECURE_ORIGIN, 1); |
| 19127 | |
| 19128 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19129 | } |
| 19130 | |
| 19131 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19132 | DontCreateReportHttpError) { |
| 19133 | base::HistogramTester histograms; |
| 19134 | RequestPolicy(); |
| 19135 | EXPECT_EQ(1u, network_error_logging_service()->headers().size()); |
| 19136 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19137 | |
| 19138 | // Make HTTP request that fails |
| 19139 | MockRead data_reads[] = { |
| 19140 | MockRead("hello world"), |
| 19141 | MockRead(SYNCHRONOUS, OK), |
| 19142 | }; |
| 19143 | |
| 19144 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
| 19145 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19146 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19147 | url_ = "http://www.originwithoutpolicy.com:2000/"; |
| 19148 | request_.url = GURL(url_); |
| 19149 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19150 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19151 | |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19152 | auto trans = |
| 19153 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19154 | TestCompletionCallback callback; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19155 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
Lily Chen | 00196ab6 | 2018-12-04 19:52:29 | [diff] [blame] | 19156 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 19157 | |
| 19158 | // Insecure request does not generate a report, regardless of existence of a |
| 19159 | // policy for the origin. |
| 19160 | histograms.ExpectBucketCount( |
| 19161 | NetworkErrorLoggingService::kRequestOutcomeHistogram, |
| 19162 | NetworkErrorLoggingService::RequestOutcome::DISCARDED_INSECURE_ORIGIN, 1); |
| 19163 | |
| 19164 | EXPECT_EQ(1u, network_error_logging_service()->errors().size()); |
| 19165 | } |
| 19166 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19167 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 19168 | ReportContainsUploadDepth) { |
| 19169 | reporting_upload_depth_ = 7; |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19170 | request_.reporting_upload_depth = reporting_upload_depth_; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19171 | RequestPolicy(); |
| 19172 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19173 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19174 | network_error_logging_service()->errors()[0]; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19175 | EXPECT_EQ(7, error.reporting_upload_depth); |
| 19176 | } |
| 19177 | |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19178 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ReportElapsedTime) { |
| 19179 | std::string extra_header_string = extra_headers_.ToString(); |
| 19180 | static const base::TimeDelta kSleepDuration = |
| 19181 | base::TimeDelta::FromMilliseconds(10); |
| 19182 | |
| 19183 | std::vector<MockWrite> data_writes = { |
| 19184 | MockWrite(ASYNC, 0, |
| 19185 | "GET / HTTP/1.1\r\n" |
| 19186 | "Host: www.example.org\r\n" |
| 19187 | "Connection: keep-alive\r\n"), |
| 19188 | MockWrite(ASYNC, 1, extra_header_string.data()), |
| 19189 | }; |
| 19190 | |
| 19191 | std::vector<MockRead> data_reads = { |
| 19192 | // Write one byte of the status line, followed by a pause. |
| 19193 | MockRead(ASYNC, 2, "H"), |
| 19194 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
| 19195 | MockRead(ASYNC, 4, "TTP/1.1 200 OK\r\n\r\n"), |
| 19196 | MockRead(ASYNC, 5, "hello world"), |
| 19197 | MockRead(SYNCHRONOUS, OK, 6), |
| 19198 | }; |
| 19199 | |
| 19200 | SequencedSocketData data(data_reads, data_writes); |
| 19201 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 19202 | |
| 19203 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 19204 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 19205 | |
| 19206 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 19207 | |
| 19208 | auto trans = |
| 19209 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 19210 | |
| 19211 | TestCompletionCallback callback; |
| 19212 | |
| 19213 | int rv = trans->Start(&request_, callback.callback(), NetLogWithSource()); |
| 19214 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 19215 | |
| 19216 | data.RunUntilPaused(); |
| 19217 | ASSERT_TRUE(data.IsPaused()); |
| 19218 | FastForwardBy(kSleepDuration); |
| 19219 | data.Resume(); |
| 19220 | |
| 19221 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 19222 | |
| 19223 | std::string response_data; |
| 19224 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 19225 | EXPECT_EQ("hello world", response_data); |
| 19226 | |
| 19227 | trans.reset(); |
| 19228 | |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19229 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19230 | |
| 19231 | CheckReport(0 /* index */, 200 /* status_code */, OK); |
| 19232 | |
| 19233 | const NetworkErrorLoggingService::RequestDetails& error = |
| 19234 | network_error_logging_service()->errors()[0]; |
| 19235 | |
| 19236 | // Sanity-check elapsed time in error report |
| 19237 | EXPECT_EQ(kSleepDuration, error.elapsed_time); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 19238 | } |
Lily Chen | fec60d9 | 2019-01-24 01:16:42 | [diff] [blame] | 19239 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 19240 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 19241 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 19242 | } // namespace net |