[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 | |
[email protected] | 68bf915 | 2008-09-25 19:47:30 | [diff] [blame] | 17 | #include "base/compiler_specific.h" |
[email protected] | 5799981 | 2013-02-24 05:40:52 | [diff] [blame] | 18 | #include "base/files/file_path.h" |
thestig | d8df033 | 2014-09-04 06:33:29 | [diff] [blame] | 19 | #include "base/files/file_util.h" |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 20 | #include "base/json/json_writer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 21 | #include "base/logging.h" |
Avi Drissman | 13fc893 | 2015-12-20 04:40:46 | [diff] [blame] | 22 | #include "base/macros.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" |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 26 | #include "base/strings/string_piece.h" |
[email protected] | 125ef48 | 2013-06-11 18:32:47 | [diff] [blame] | 27 | #include "base/strings/string_util.h" |
[email protected] | 750b2f3c | 2013-06-07 18:41:05 | [diff] [blame] | 28 | #include "base/strings/utf_string_conversions.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 29 | #include "base/test/metrics/histogram_tester.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 30 | #include "base/test/simple_test_clock.h" |
| 31 | #include "base/test/simple_test_tick_clock.h" |
[email protected] | f36a813 | 2011-09-02 18:36:33 | [diff] [blame] | 32 | #include "base/test/test_file_util.h" |
gab | f767595f | 2016-05-11 18:50:35 | [diff] [blame] | 33 | #include "base/threading/thread_task_runner_handle.h" |
[email protected] | 277d594 | 2010-08-11 21:02:35 | [diff] [blame] | 34 | #include "net/base/auth.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 35 | #include "net/base/chunked_upload_data_stream.h" |
Bence Béky | a25e3f7 | 2018-02-13 21:13:39 | [diff] [blame] | 36 | #include "net/base/completion_once_callback.h" |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 37 | #include "net/base/elements_upload_data_stream.h" |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 38 | #include "net/base/load_timing_info.h" |
| 39 | #include "net/base/load_timing_info_test_util.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 40 | #include "net/base/net_errors.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 41 | #include "net/base/proxy_delegate.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 42 | #include "net/base/proxy_server.h" |
[email protected] | ac790b4 | 2009-12-02 04:31:31 | [diff] [blame] | 43 | #include "net/base/request_priority.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 44 | #include "net/base/test_completion_callback.h" |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 45 | #include "net/base/test_proxy_delegate.h" |
[email protected] | b2d26cfd | 2012-12-11 10:36:06 | [diff] [blame] | 46 | #include "net/base/upload_bytes_element_reader.h" |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 47 | #include "net/base/upload_file_element_reader.h" |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 48 | #include "net/cert/cert_status_flags.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 49 | #include "net/cert/mock_cert_verifier.h" |
[email protected] | bc71b877 | 2013-04-10 20:55:16 | [diff] [blame] | 50 | #include "net/dns/host_cache.h" |
[email protected] | f2cb3cf | 2013-03-21 01:40:53 | [diff] [blame] | 51 | #include "net/dns/mock_host_resolver.h" |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 52 | #include "net/http/http_auth_challenge_tokenizer.h" |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 53 | #include "net/http/http_auth_handler_digest.h" |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 54 | #include "net/http/http_auth_handler_mock.h" |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 55 | #include "net/http/http_auth_handler_ntlm.h" |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 56 | #include "net/http/http_auth_scheme.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 57 | #include "net/http/http_basic_stream.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 58 | #include "net/http/http_network_session.h" |
[email protected] | 87bfa3f | 2010-09-30 14:54:56 | [diff] [blame] | 59 | #include "net/http/http_network_session_peer.h" |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 60 | #include "net/http/http_request_headers.h" |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 61 | #include "net/http/http_response_info.h" |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 62 | #include "net/http/http_server_properties_impl.h" |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 63 | #include "net/http/http_stream.h" |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 64 | #include "net/http/http_stream_factory.h" |
[email protected] | c41737d | 2014-05-14 07:47:19 | [diff] [blame] | 65 | #include "net/http/http_transaction_test_util.h" |
eroman | 87c53d6 | 2015-04-02 06:51:07 | [diff] [blame] | 66 | #include "net/log/net_log.h" |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 67 | #include "net/log/net_log_event_type.h" |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 68 | #include "net/log/net_log_source.h" |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 69 | #include "net/log/test_net_log.h" |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 70 | #include "net/log/test_net_log_entry.h" |
| 71 | #include "net/log/test_net_log_util.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 72 | #include "net/proxy_resolution/mock_proxy_resolver.h" |
| 73 | #include "net/proxy_resolution/proxy_config_service_fixed.h" |
| 74 | #include "net/proxy_resolution/proxy_info.h" |
Lily Houghton | ffe89daa0 | 2018-03-09 18:30:03 | [diff] [blame] | 75 | #include "net/proxy_resolution/proxy_resolution_service.h" |
Lily Houghton | 582d462 | 2018-01-22 22:43:40 | [diff] [blame] | 76 | #include "net/proxy_resolution/proxy_resolver.h" |
| 77 | #include "net/proxy_resolution/proxy_resolver_factory.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 78 | #include "net/socket/client_socket_factory.h" |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 79 | #include "net/socket/client_socket_pool.h" |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 80 | #include "net/socket/client_socket_pool_manager.h" |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 81 | #include "net/socket/connection_attempts.h" |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 82 | #include "net/socket/mock_client_socket_pool_manager.h" |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 83 | #include "net/socket/next_proto.h" |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 84 | #include "net/socket/socket_tag.h" |
[email protected] | f7984fc6 | 2009-06-22 23:26:44 | [diff] [blame] | 85 | #include "net/socket/socket_test_util.h" |
| 86 | #include "net/socket/ssl_client_socket.h" |
Bence Béky | 94658bf | 2018-05-11 19:22:58 | [diff] [blame] | 87 | #include "net/spdy/spdy_session.h" |
| 88 | #include "net/spdy/spdy_session_pool.h" |
| 89 | #include "net/spdy/spdy_test_util_common.h" |
nharper | b7441ef | 2016-01-25 23:54:14 | [diff] [blame] | 90 | #include "net/ssl/default_channel_id_store.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 91 | #include "net/ssl/ssl_cert_request_info.h" |
[email protected] | e86839fd | 2013-08-14 18:29:03 | [diff] [blame] | 92 | #include "net/ssl/ssl_config_service.h" |
[email protected] | 536fd0b | 2013-03-14 17:41:57 | [diff] [blame] | 93 | #include "net/ssl/ssl_info.h" |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 94 | #include "net/ssl/ssl_private_key.h" |
[email protected] | 6e7845ae | 2013-03-29 21:48:11 | [diff] [blame] | 95 | #include "net/test/cert_test_util.h" |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 96 | #include "net/test/gtest_util.h" |
rsleevi | a69c79a | 2016-06-22 03:28:43 | [diff] [blame] | 97 | #include "net/test/test_data_directory.h" |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 98 | #include "net/test/test_with_scoped_task_environment.h" |
Ryan Hamilton | 2e003eea | 2018-05-02 00:24:29 | [diff] [blame] | 99 | #include "net/third_party/spdy/core/spdy_framer.h" |
[email protected] | baee31a | 2018-01-18 06:10:23 | [diff] [blame] | 100 | #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
[email protected] | 831e4a3 | 2013-11-14 02:14:44 | [diff] [blame] | 101 | #include "net/websockets/websocket_handshake_stream_base.h" |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 102 | #include "net/websockets/websocket_test_util.h" |
bnc | f458840 | 2015-11-24 13:33:18 | [diff] [blame] | 103 | #include "testing/gmock/include/gmock/gmock.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 104 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 23887f04f | 2008-12-02 19:20:15 | [diff] [blame] | 105 | #include "testing/platform_test.h" |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 106 | #include "url/gurl.h" |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 107 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 108 | #if defined(NTLM_PORTABLE) |
| 109 | #include "base/base64.h" |
| 110 | #include "net/ntlm/ntlm_test_data.h" |
| 111 | #endif |
| 112 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 113 | #if BUILDFLAG(ENABLE_REPORTING) |
| 114 | #include "net/network_error_logging/network_error_logging_service.h" |
| 115 | #include "net/network_error_logging/network_error_logging_test_util.h" |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 116 | #include "net/reporting/reporting_cache.h" |
| 117 | #include "net/reporting/reporting_client.h" |
| 118 | #include "net/reporting/reporting_header_parser.h" |
| 119 | #include "net/reporting/reporting_service.h" |
| 120 | #include "net/reporting/reporting_test_util.h" |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 121 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 122 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 123 | using net::test::IsError; |
| 124 | using net::test::IsOk; |
| 125 | |
[email protected] | ad65a3e | 2013-12-25 18:18:01 | [diff] [blame] | 126 | using base::ASCIIToUTF16; |
| 127 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 128 | //----------------------------------------------------------------------------- |
| 129 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 130 | namespace net { |
| 131 | |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 132 | namespace { |
| 133 | |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 134 | const base::string16 kBar(ASCIIToUTF16("bar")); |
| 135 | const base::string16 kBar2(ASCIIToUTF16("bar2")); |
| 136 | const base::string16 kBar3(ASCIIToUTF16("bar3")); |
| 137 | const base::string16 kBaz(ASCIIToUTF16("baz")); |
| 138 | const base::string16 kFirst(ASCIIToUTF16("first")); |
| 139 | const base::string16 kFoo(ASCIIToUTF16("foo")); |
| 140 | const base::string16 kFoo2(ASCIIToUTF16("foo2")); |
| 141 | const base::string16 kFoo3(ASCIIToUTF16("foo3")); |
| 142 | const base::string16 kFou(ASCIIToUTF16("fou")); |
| 143 | const base::string16 kSecond(ASCIIToUTF16("second")); |
[email protected] | 42cba2fb | 2013-03-29 19:58:57 | [diff] [blame] | 144 | const base::string16 kWrongPassword(ASCIIToUTF16("wrongpassword")); |
[email protected] | 13c8a09 | 2010-07-29 06:15:44 | [diff] [blame] | 145 | |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 146 | const char kAlternativeServiceHttpHeader[] = |
| 147 | "Alt-Svc: h2=\"mail.example.org:443\"\r\n"; |
| 148 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 149 | int GetIdleSocketCountInTransportSocketPool(HttpNetworkSession* session) { |
| 150 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 151 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 152 | } |
| 153 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 154 | int GetIdleSocketCountInSSLSocketPool(HttpNetworkSession* session) { |
| 155 | return session->GetSSLSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 156 | ->IdleSocketCount(); |
[email protected] | e5c02664 | 2012-03-17 00:14:02 | [diff] [blame] | 157 | } |
| 158 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 159 | bool IsTransportSocketPoolStalled(HttpNetworkSession* session) { |
| 160 | return session->GetTransportSocketPool(HttpNetworkSession::NORMAL_SOCKET_POOL) |
| 161 | ->IsStalled(); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 162 | } |
| 163 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 164 | // Takes in a Value created from a NetLogHttpResponseParameter, and returns |
| 165 | // a JSONified list of headers as a single string. Uses single quotes instead |
| 166 | // of double quotes for easier comparison. Returns false on failure. |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 167 | bool GetHeaders(base::DictionaryValue* params, std::string* headers) { |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 168 | if (!params) |
| 169 | return false; |
[email protected] | ea5ef4c | 2013-06-13 22:50:27 | [diff] [blame] | 170 | base::ListValue* header_list; |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 171 | if (!params->GetList("headers", &header_list)) |
| 172 | return false; |
| 173 | std::string double_quote_headers; |
estade | 8d04646 | 2015-05-16 01:02:34 | [diff] [blame] | 174 | base::JSONWriter::Write(*header_list, &double_quote_headers); |
[email protected] | 466c986 | 2013-12-03 22:05:28 | [diff] [blame] | 175 | base::ReplaceChars(double_quote_headers, "\"", "'", headers); |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 176 | return true; |
| 177 | } |
| 178 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 179 | // Tests LoadTimingInfo in the case a socket is reused and no PAC script is |
| 180 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 181 | void TestLoadTimingReused(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 182 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 183 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 184 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 185 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 186 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 187 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 188 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 189 | EXPECT_FALSE(load_timing_info.send_start.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 190 | |
| 191 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 192 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 193 | // Set at a higher level. |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 194 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 195 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 196 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 197 | } |
| 198 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 199 | // Tests LoadTimingInfo in the case a new socket is used and no PAC script is |
| 200 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 201 | void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 202 | int connect_timing_flags) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 203 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 204 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 205 | |
| 206 | EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 207 | EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 208 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 209 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 210 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 211 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 212 | load_timing_info.send_start); |
| 213 | |
| 214 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 215 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 216 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 217 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 218 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 219 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | // Tests LoadTimingInfo in the case a socket is reused and a PAC script is |
| 223 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 224 | void TestLoadTimingReusedWithPac(const LoadTimingInfo& load_timing_info) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 225 | EXPECT_TRUE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 226 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 227 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 228 | ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 229 | |
| 230 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 231 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 232 | load_timing_info.proxy_resolve_end); |
| 233 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 234 | load_timing_info.send_start); |
| 235 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 236 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 237 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 238 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 239 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 240 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | // Tests LoadTimingInfo in the case a new socket is used and a PAC script is |
| 244 | // used. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 245 | void TestLoadTimingNotReusedWithPac(const LoadTimingInfo& load_timing_info, |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 246 | int connect_timing_flags) { |
| 247 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 248 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 249 | |
| 250 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 251 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 252 | load_timing_info.proxy_resolve_end); |
| 253 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 254 | load_timing_info.connect_timing.connect_start); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 255 | ExpectConnectTimingHasTimes(load_timing_info.connect_timing, |
| 256 | connect_timing_flags); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 257 | EXPECT_LE(load_timing_info.connect_timing.connect_end, |
| 258 | load_timing_info.send_start); |
| 259 | |
| 260 | EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 261 | |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 262 | // Set at a higher level. |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 263 | EXPECT_TRUE(load_timing_info.request_start_time.is_null()); |
| 264 | EXPECT_TRUE(load_timing_info.request_start.is_null()); |
[email protected] | 3b23a22 | 2013-05-15 21:33:25 | [diff] [blame] | 265 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 266 | } |
| 267 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 268 | std::unique_ptr<HttpNetworkSession> CreateSession( |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 269 | SpdySessionDependencies* session_deps) { |
[email protected] | c6bf815 | 2012-12-02 07:43:34 | [diff] [blame] | 270 | return SpdySessionDependencies::SpdyCreateSession(session_deps); |
[email protected] | e8d53619 | 2008-10-17 22:21:14 | [diff] [blame] | 271 | } |
| 272 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 273 | class FailingProxyResolverFactory : public ProxyResolverFactory { |
| 274 | public: |
| 275 | FailingProxyResolverFactory() : ProxyResolverFactory(false) {} |
| 276 | |
| 277 | // ProxyResolverFactory override. |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 278 | int CreateProxyResolver(const scoped_refptr<PacFileData>& script_data, |
| 279 | std::unique_ptr<ProxyResolver>* result, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 280 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 281 | std::unique_ptr<Request>* request) override { |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 282 | return ERR_PAC_SCRIPT_FAILED; |
| 283 | } |
| 284 | }; |
| 285 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 286 | class TestSSLConfigService : public SSLConfigService { |
| 287 | public: |
| 288 | explicit TestSSLConfigService(const SSLConfig& config) : config_(config) {} |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 289 | ~TestSSLConfigService() override = default; |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 290 | |
| 291 | void GetSSLConfig(SSLConfig* config) override { *config = config_; } |
| 292 | |
Nick Harper | 89bc721 | 2018-07-31 19:07:57 | [diff] [blame] | 293 | bool CanShareConnectionWithClientCerts( |
| 294 | const std::string& hostname) const override { |
| 295 | return false; |
| 296 | } |
| 297 | |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 298 | private: |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 299 | SSLConfig config_; |
| 300 | }; |
| 301 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 302 | } // namespace |
| 303 | |
Bence Béky | 98447b1 | 2018-05-08 03:14:01 | [diff] [blame] | 304 | class HttpNetworkTransactionTest : public PlatformTest, |
| 305 | public WithScopedTaskEnvironment { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 306 | public: |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 307 | ~HttpNetworkTransactionTest() override { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 308 | // Important to restore the per-pool limit first, since the pool limit must |
| 309 | // always be greater than group limit, and the tests reduce both limits. |
| 310 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 311 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_pool_sockets_); |
| 312 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 313 | HttpNetworkSession::NORMAL_SOCKET_POOL, old_max_group_sockets_); |
| 314 | } |
| 315 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 316 | protected: |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 317 | HttpNetworkTransactionTest() |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 318 | : ssl_(ASYNC, OK), |
| 319 | old_max_group_sockets_(ClientSocketPoolManager::max_sockets_per_group( |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 320 | HttpNetworkSession::NORMAL_SOCKET_POOL)), |
| 321 | old_max_pool_sockets_(ClientSocketPoolManager::max_sockets_per_pool( |
| 322 | HttpNetworkSession::NORMAL_SOCKET_POOL)) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 323 | session_deps_.enable_http2_alternative_service = true; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 324 | } |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 325 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 326 | struct SimpleGetHelperResult { |
| 327 | int rv; |
| 328 | std::string status_line; |
| 329 | std::string response_data; |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 330 | int64_t total_received_bytes; |
| 331 | int64_t total_sent_bytes; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 332 | LoadTimingInfo load_timing_info; |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 333 | ConnectionAttempts connection_attempts; |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 334 | IPEndPoint remote_endpoint_after_start; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 335 | }; |
| 336 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 337 | void SetUp() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 338 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 339 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 340 | } |
| 341 | |
dcheng | 67be2b1f | 2014-10-27 21:47:29 | [diff] [blame] | 342 | void TearDown() override { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 343 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 344 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 345 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 346 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 347 | PlatformTest::TearDown(); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 348 | NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 349 | base::RunLoop().RunUntilIdle(); |
[email protected] | 0e75a73 | 2008-10-16 20:36:09 | [diff] [blame] | 350 | } |
| 351 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 352 | // Either |write_failure| specifies a write failure or |read_failure| |
| 353 | // specifies a read failure when using a reused socket. In either case, the |
| 354 | // failure should cause the network transaction to resend the request, and the |
| 355 | // other argument should be NULL. |
| 356 | void KeepAliveConnectionResendRequestTest(const MockWrite* write_failure, |
| 357 | const MockRead* read_failure); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 358 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 359 | // Either |write_failure| specifies a write failure or |read_failure| |
| 360 | // specifies a read failure when using a reused socket. In either case, the |
| 361 | // failure should cause the network transaction to resend the request, and the |
| 362 | // other argument should be NULL. |
| 363 | void PreconnectErrorResendRequestTest(const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 364 | const MockRead* read_failure, |
| 365 | bool use_spdy); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 366 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 367 | SimpleGetHelperResult SimpleGetHelperForData( |
| 368 | base::span<StaticSocketDataProvider*> providers) { |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 369 | SimpleGetHelperResult out; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 370 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 371 | HttpRequestInfo request; |
| 372 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 373 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 374 | request.traffic_annotation = |
| 375 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 376 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 377 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 378 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 379 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 380 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 381 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 382 | for (auto* provider : providers) { |
| 383 | session_deps_.socket_factory->AddSocketDataProvider(provider); |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 384 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 385 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 386 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 387 | |
eroman | 24bc6a1 | 2015-05-06 19:55:48 | [diff] [blame] | 388 | EXPECT_TRUE(log.bound().IsCapturing()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 389 | int rv = trans.Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 390 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 391 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 392 | out.rv = callback.WaitForResult(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 393 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
| 394 | out.total_sent_bytes = trans.GetTotalSentBytes(); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 395 | |
| 396 | // Even in the failure cases that use this function, connections are always |
| 397 | // successfully established before the error. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 398 | EXPECT_TRUE(trans.GetLoadTimingInfo(&out.load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 399 | TestLoadTimingNotReused(out.load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 400 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 401 | if (out.rv != OK) |
| 402 | return out; |
| 403 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 404 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 405 | // Can't use ASSERT_* inside helper functions like this, so |
| 406 | // return an error. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 407 | if (!response || !response->headers) { |
[email protected] | fe2255a | 2011-09-20 19:37:50 | [diff] [blame] | 408 | out.rv = ERR_UNEXPECTED; |
| 409 | return out; |
| 410 | } |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 411 | out.status_line = response->headers->GetStatusLine(); |
| 412 | |
[email protected] | 80a09a8 | 2012-11-16 17:40:06 | [diff] [blame] | 413 | EXPECT_EQ("127.0.0.1", response->socket_address.host()); |
| 414 | EXPECT_EQ(80, response->socket_address.port()); |
[email protected] | 6d81b48 | 2011-02-22 19:47:19 | [diff] [blame] | 415 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 416 | bool got_endpoint = |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 417 | trans.GetRemoteEndpoint(&out.remote_endpoint_after_start); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 418 | EXPECT_EQ(got_endpoint, |
| 419 | out.remote_endpoint_after_start.address().size() > 0); |
| 420 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 421 | rv = ReadTransaction(&trans, &out.response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 422 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 423 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 424 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 425 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 426 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 427 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_REQUEST_HEADERS, |
| 428 | NetLogEventPhase::NONE); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 429 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 430 | entries, pos, NetLogEventType::HTTP_TRANSACTION_READ_RESPONSE_HEADERS, |
| 431 | NetLogEventPhase::NONE); |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 432 | |
[email protected] | f3da152d | 2012-06-02 01:00:57 | [diff] [blame] | 433 | std::string line; |
| 434 | EXPECT_TRUE(entries[pos].GetStringValue("line", &line)); |
| 435 | EXPECT_EQ("GET / HTTP/1.1\r\n", line); |
| 436 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 437 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 438 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 439 | std::string value; |
| 440 | EXPECT_TRUE(request_headers.GetHeader("Host", &value)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 441 | EXPECT_EQ("www.example.org", value); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 442 | EXPECT_TRUE(request_headers.GetHeader("Connection", &value)); |
| 443 | EXPECT_EQ("keep-alive", value); |
| 444 | |
| 445 | std::string response_headers; |
| 446 | EXPECT_TRUE(GetHeaders(entries[pos].params.get(), &response_headers)); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 447 | EXPECT_EQ("['Host: www.example.org','Connection: keep-alive']", |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 448 | response_headers); |
[email protected] | 3deb9a5 | 2010-11-11 00:24:40 | [diff] [blame] | 449 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 450 | out.total_received_bytes = trans.GetTotalReceivedBytes(); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 451 | // The total number of sent bytes should not have changed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 452 | EXPECT_EQ(out.total_sent_bytes, trans.GetTotalSentBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 453 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 454 | trans.GetConnectionAttempts(&out.connection_attempts); |
[email protected] | aecfbf2 | 2008-10-16 02:02:47 | [diff] [blame] | 455 | return out; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 456 | } |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 457 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 458 | SimpleGetHelperResult SimpleGetHelper(base::span<const MockRead> data_reads) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 459 | MockWrite data_writes[] = { |
| 460 | MockWrite("GET / HTTP/1.1\r\n" |
| 461 | "Host: www.example.org\r\n" |
| 462 | "Connection: keep-alive\r\n\r\n"), |
| 463 | }; |
[email protected] | 5a60c8b | 2011-10-19 20:14:29 | [diff] [blame] | 464 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 465 | StaticSocketDataProvider reads(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 466 | StaticSocketDataProvider* data[] = {&reads}; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 467 | SimpleGetHelperResult out = SimpleGetHelperForData(data); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 468 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 469 | EXPECT_EQ(CountWriteBytes(data_writes), out.total_sent_bytes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 470 | return out; |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 471 | } |
| 472 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 473 | void AddSSLSocketData() { |
| 474 | ssl_.next_proto = kProtoHTTP2; |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 475 | ssl_.ssl_info.cert = |
| 476 | ImportCertFromFile(GetTestCertsDirectory(), "spdy_pooling.pem"); |
| 477 | ASSERT_TRUE(ssl_.ssl_info.cert); |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 478 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_); |
| 479 | } |
| 480 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 481 | void ConnectStatusHelperWithExpectedStatus(const MockRead& status, |
| 482 | int expected_status); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 483 | |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 484 | void ConnectStatusHelper(const MockRead& status); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 485 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 486 | void CheckErrorIsPassedBack(int error, IoMode mode); |
| 487 | |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 488 | // These clocks are defined here, even though they're only used in the |
| 489 | // Reporting tests below, since they need to be destroyed after |
| 490 | // |session_deps_|. |
| 491 | base::SimpleTestClock clock_; |
| 492 | base::SimpleTestTickClock tick_clock_; |
| 493 | |
[email protected] | 4bd4622 | 2013-05-14 19:32:23 | [diff] [blame] | 494 | SpdyTestUtil spdy_util_; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 495 | SpdySessionDependencies session_deps_; |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 496 | SSLSocketDataProvider ssl_; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 497 | |
| 498 | // Original socket limits. Some tests set these. Safest to always restore |
| 499 | // them once each test has been run. |
| 500 | int old_max_group_sockets_; |
| 501 | int old_max_pool_sockets_; |
[email protected] | ff007e16 | 2009-05-23 09:13:15 | [diff] [blame] | 502 | }; |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 503 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 504 | namespace { |
| 505 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 506 | class BeforeHeadersSentHandler { |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 507 | public: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 508 | BeforeHeadersSentHandler() |
| 509 | : observed_before_headers_sent_with_proxy_(false), |
| 510 | observed_before_headers_sent_(false) {} |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 511 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 512 | void OnBeforeHeadersSent(const ProxyInfo& proxy_info, |
| 513 | HttpRequestHeaders* request_headers) { |
| 514 | observed_before_headers_sent_ = true; |
| 515 | if (!proxy_info.is_http() && !proxy_info.is_https() && |
| 516 | !proxy_info.is_quic()) { |
| 517 | return; |
| 518 | } |
| 519 | observed_before_headers_sent_with_proxy_ = true; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 520 | observed_proxy_server_uri_ = proxy_info.proxy_server().ToURI(); |
| 521 | } |
| 522 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 523 | bool observed_before_headers_sent_with_proxy() const { |
| 524 | return observed_before_headers_sent_with_proxy_; |
| 525 | } |
| 526 | |
| 527 | bool observed_before_headers_sent() const { |
| 528 | return observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | std::string observed_proxy_server_uri() const { |
| 532 | return observed_proxy_server_uri_; |
| 533 | } |
| 534 | |
| 535 | private: |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 536 | bool observed_before_headers_sent_with_proxy_; |
| 537 | bool observed_before_headers_sent_; |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 538 | std::string observed_proxy_server_uri_; |
| 539 | |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 540 | DISALLOW_COPY_AND_ASSIGN(BeforeHeadersSentHandler); |
[email protected] | 597a1ab | 2014-06-26 08:12:27 | [diff] [blame] | 541 | }; |
| 542 | |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 543 | // Fill |str| with a long header list that consumes >= |size| bytes. |
| 544 | void FillLargeHeadersString(std::string* str, int size) { |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 545 | const char row[] = |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 546 | "SomeHeaderName: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\r\n"; |
| 547 | const int sizeof_row = strlen(row); |
| 548 | const int num_rows = static_cast<int>( |
| 549 | ceil(static_cast<float>(size) / sizeof_row)); |
| 550 | const int sizeof_data = num_rows * sizeof_row; |
| 551 | DCHECK(sizeof_data >= size); |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 552 | str->reserve(sizeof_data); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 553 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 554 | for (int i = 0; i < num_rows; ++i) |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 555 | str->append(row, sizeof_row); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 556 | } |
| 557 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 558 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 559 | uint64_t MockGetMSTime() { |
| 560 | // Tue, 23 May 2017 20:13:07 +0000 |
| 561 | return 131400439870000000; |
| 562 | } |
| 563 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 564 | // Alternative functions that eliminate randomness and dependency on the local |
| 565 | // host name so that the generated NTLM messages are reproducible. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 566 | void MockGenerateRandom(uint8_t* output, size_t n) { |
| 567 | // This is set to 0xaa because the client challenge for testing in |
| 568 | // [MS-NLMP] Section 4.2.1 is 8 bytes of 0xaa. |
| 569 | memset(output, 0xaa, n); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 570 | } |
| 571 | |
[email protected] | fe2bc6a | 2009-03-23 16:52:20 | [diff] [blame] | 572 | std::string MockGetHostName() { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 573 | return ntlm::test::kHostnameAscii; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 574 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 575 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 576 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 577 | template<typename ParentPool> |
| 578 | class CaptureGroupNameSocketPool : public ParentPool { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 579 | public: |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 580 | CaptureGroupNameSocketPool(HostResolver* host_resolver, |
| 581 | CertVerifier* cert_verifier); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 582 | |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 583 | const std::string last_group_name_received() const { |
| 584 | return last_group_name_; |
| 585 | } |
| 586 | |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 587 | bool socket_requested() const { return socket_requested_; } |
| 588 | |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 589 | int RequestSocket(const std::string& group_name, |
| 590 | const void* socket_params, |
| 591 | RequestPriority priority, |
Paul Jensen | 8d6f87ec | 2018-01-13 00:46:54 | [diff] [blame] | 592 | const SocketTag& socket_tag, |
mmenke | d3641e1 | 2016-01-28 16:06:15 | [diff] [blame] | 593 | ClientSocketPool::RespectLimits respect_limits, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 594 | ClientSocketHandle* handle, |
Bence Béky | 5a8662b | 2018-07-03 13:04:03 | [diff] [blame] | 595 | CompletionOnceCallback callback, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 596 | const NetLogWithSource& net_log) override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 597 | last_group_name_ = group_name; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 598 | socket_requested_ = true; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 599 | return ERR_IO_PENDING; |
| 600 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 601 | void CancelRequest(const std::string& group_name, |
| 602 | ClientSocketHandle* handle) override {} |
| 603 | void ReleaseSocket(const std::string& group_name, |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 604 | std::unique_ptr<StreamSocket> socket, |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 605 | int id) override {} |
| 606 | void CloseIdleSockets() override {} |
xunjieli | 92feb33 | 2017-03-03 17:19:23 | [diff] [blame] | 607 | void CloseIdleSocketsInGroup(const std::string& group_name) override {} |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 608 | int IdleSocketCount() const override { return 0; } |
| 609 | int IdleSocketCountInGroup(const std::string& group_name) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 610 | return 0; |
| 611 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 612 | LoadState GetLoadState(const std::string& group_name, |
| 613 | const ClientSocketHandle* handle) const override { |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 614 | return LOAD_STATE_IDLE; |
| 615 | } |
dmichael | d6e570d | 2014-12-18 22:30:57 | [diff] [blame] | 616 | base::TimeDelta ConnectionTimeout() const override { |
[email protected] | a796bcec | 2010-03-22 17:17:26 | [diff] [blame] | 617 | return base::TimeDelta(); |
| 618 | } |
[email protected] | d80a432 | 2009-08-14 07:07:49 | [diff] [blame] | 619 | |
| 620 | private: |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 621 | std::string last_group_name_; |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 622 | bool socket_requested_ = false; |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 623 | }; |
| 624 | |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 625 | typedef CaptureGroupNameSocketPool<TransportClientSocketPool> |
| 626 | CaptureGroupNameTransportSocketPool; |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 627 | typedef CaptureGroupNameSocketPool<HttpProxyClientSocketPool> |
| 628 | CaptureGroupNameHttpProxySocketPool; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 629 | typedef CaptureGroupNameSocketPool<SOCKSClientSocketPool> |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 630 | CaptureGroupNameSOCKSSocketPool; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 631 | typedef CaptureGroupNameSocketPool<SSLClientSocketPool> |
| 632 | CaptureGroupNameSSLSocketPool; |
| 633 | |
rkaplow | d90695c | 2015-03-25 22:12:41 | [diff] [blame] | 634 | template <typename ParentPool> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 635 | CaptureGroupNameSocketPool<ParentPool>::CaptureGroupNameSocketPool( |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 636 | HostResolver* host_resolver, |
| 637 | CertVerifier* /* cert_verifier */) |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 638 | : ParentPool(0, 0, host_resolver, NULL, NULL, NULL) {} |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 639 | |
hashimoto | 0d3e4fb | 2015-01-09 05:02:50 | [diff] [blame] | 640 | template <> |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 641 | CaptureGroupNameHttpProxySocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 642 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 643 | CertVerifier* /* cert_verifier */) |
tbansal | 16196a1e | 2017-06-09 01:50:09 | [diff] [blame] | 644 | : HttpProxyClientSocketPool(0, 0, NULL, NULL, NULL, NULL) {} |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 645 | |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 646 | template <> |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 647 | CaptureGroupNameSSLSocketPool::CaptureGroupNameSocketPool( |
hashimoto | dae13b0 | 2015-01-15 04:28:21 | [diff] [blame] | 648 | HostResolver* /* host_resolver */, |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 649 | CertVerifier* cert_verifier) |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 650 | : SSLClientSocketPool(0, |
| 651 | 0, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 652 | cert_verifier, |
| 653 | NULL, |
| 654 | NULL, |
[email protected] | 284303b6 | 2013-11-28 15:11:54 | [diff] [blame] | 655 | NULL, |
eranm | 6571b2b | 2014-12-03 15:53:23 | [diff] [blame] | 656 | NULL, |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 657 | std::string(), |
| 658 | NULL, |
| 659 | NULL, |
| 660 | NULL, |
| 661 | NULL, |
| 662 | NULL, |
[email protected] | 8e45855 | 2014-08-05 00:02:15 | [diff] [blame] | 663 | NULL) { |
| 664 | } |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 665 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 666 | //----------------------------------------------------------------------------- |
| 667 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 668 | // Helper functions for validating that AuthChallengeInfo's are correctly |
| 669 | // configured for common cases. |
| 670 | bool CheckBasicServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 671 | if (!auth_challenge) |
| 672 | return false; |
| 673 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 674 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 675 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 676 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 677 | return true; |
| 678 | } |
| 679 | |
| 680 | bool CheckBasicProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 681 | if (!auth_challenge) |
| 682 | return false; |
| 683 | EXPECT_TRUE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 684 | EXPECT_EQ("http://myproxy:70", auth_challenge->challenger.Serialize()); |
| 685 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
| 686 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
| 687 | return true; |
| 688 | } |
| 689 | |
| 690 | bool CheckBasicSecureProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 691 | if (!auth_challenge) |
| 692 | return false; |
| 693 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 694 | EXPECT_EQ("https://myproxy:70", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 695 | EXPECT_EQ("MyRealm1", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 696 | EXPECT_EQ(kBasicAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 697 | return true; |
| 698 | } |
| 699 | |
| 700 | bool CheckDigestServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 701 | if (!auth_challenge) |
| 702 | return false; |
| 703 | EXPECT_FALSE(auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 704 | EXPECT_EQ("http://www.example.org", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 705 | EXPECT_EQ("digestive", auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 706 | EXPECT_EQ(kDigestAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 707 | return true; |
| 708 | } |
| 709 | |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 710 | #if defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 711 | bool CheckNTLMServerAuth(const AuthChallengeInfo* auth_challenge) { |
| 712 | if (!auth_challenge) |
| 713 | return false; |
| 714 | EXPECT_FALSE(auth_challenge->is_proxy); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 715 | EXPECT_EQ("https://server", auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 716 | EXPECT_EQ(std::string(), auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 717 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 718 | return true; |
| 719 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 720 | |
| 721 | bool CheckNTLMProxyAuth(const AuthChallengeInfo* auth_challenge) { |
| 722 | if (!auth_challenge) |
| 723 | return false; |
| 724 | EXPECT_TRUE(auth_challenge->is_proxy); |
| 725 | EXPECT_EQ("http://server", auth_challenge->challenger.Serialize()); |
| 726 | EXPECT_EQ(std::string(), auth_challenge->realm); |
| 727 | EXPECT_EQ(kNtlmAuthScheme, auth_challenge->scheme); |
| 728 | return true; |
| 729 | } |
thakis | 84dff94 | 2015-07-28 20:47:38 | [diff] [blame] | 730 | #endif // defined(NTLM_PORTABLE) |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 731 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 732 | } // namespace |
| 733 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 734 | TEST_F(HttpNetworkTransactionTest, Basic) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 735 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 736 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 737 | } |
| 738 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 739 | TEST_F(HttpNetworkTransactionTest, SimpleGET) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 740 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 741 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 742 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 743 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 744 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 745 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 746 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 747 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 748 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 749 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 750 | EXPECT_EQ(reads_size, out.total_received_bytes); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 751 | EXPECT_EQ(0u, out.connection_attempts.size()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 752 | |
| 753 | EXPECT_FALSE(out.remote_endpoint_after_start.address().empty()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 754 | } |
| 755 | |
| 756 | // Response with no status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 757 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeaders) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 758 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 759 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 760 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 761 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 762 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 763 | EXPECT_THAT(out.rv, IsOk()); |
| 764 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 765 | EXPECT_EQ("hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 766 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 767 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 768 | } |
| 769 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 770 | // Response with no status line, and a weird port. Should fail by default. |
| 771 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPort) { |
| 772 | MockRead data_reads[] = { |
| 773 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 774 | }; |
| 775 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 776 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 777 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 778 | |
| 779 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 780 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 781 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 782 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 783 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 784 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 785 | request.method = "GET"; |
| 786 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 787 | request.traffic_annotation = |
| 788 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 789 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 790 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 791 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 792 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_INVALID_HTTP_RESPONSE)); |
| 793 | } |
| 794 | |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 795 | // Tests that request info can be destroyed after the headers phase is complete. |
| 796 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoReadDestroyRequestInfo) { |
| 797 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 798 | auto trans = |
| 799 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
| 800 | |
| 801 | MockRead data_reads[] = { |
| 802 | MockRead("HTTP/1.0 200 OK\r\n"), MockRead("Connection: keep-alive\r\n"), |
| 803 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, 0), |
| 804 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 805 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 806 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 807 | |
| 808 | TestCompletionCallback callback; |
| 809 | |
| 810 | { |
| 811 | auto request = std::make_unique<HttpRequestInfo>(); |
| 812 | request->method = "GET"; |
| 813 | request->url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 814 | request->traffic_annotation = |
| 815 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Shivani Sharma | fdcaefd | 2017-11-02 00:12:26 | [diff] [blame] | 816 | |
| 817 | int rv = |
| 818 | trans->Start(request.get(), callback.callback(), NetLogWithSource()); |
| 819 | |
| 820 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 821 | } // Let request info be destroyed. |
| 822 | |
| 823 | trans.reset(); |
| 824 | } |
| 825 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 826 | // Response with no status line, and a weird port. Option to allow weird ports |
| 827 | // enabled. |
| 828 | TEST_F(HttpNetworkTransactionTest, SimpleGETNoHeadersWeirdPortAllowed) { |
| 829 | MockRead data_reads[] = { |
| 830 | MockRead("hello world"), MockRead(SYNCHRONOUS, OK), |
| 831 | }; |
| 832 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 833 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 834 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 835 | session_deps_.http_09_on_non_default_ports_enabled = true; |
| 836 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 837 | |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 838 | HttpRequestInfo request; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 839 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 840 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 841 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 842 | request.method = "GET"; |
| 843 | request.url = GURL("http://www.example.com:2000/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 844 | request.traffic_annotation = |
| 845 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 846 | |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 847 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 848 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a7da6da | 2016-09-01 21:56:52 | [diff] [blame] | 849 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 850 | |
| 851 | const HttpResponseInfo* info = trans->GetResponseInfo(); |
| 852 | ASSERT_TRUE(info->headers); |
| 853 | EXPECT_EQ("HTTP/0.9 200 OK", info->headers->GetStatusLine()); |
| 854 | |
| 855 | // Don't bother to read the body - that's verified elsewhere, important thing |
| 856 | // is that the option to allow HTTP/0.9 on non-default ports is respected. |
| 857 | } |
| 858 | |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 859 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 860 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk3Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 861 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 862 | MockRead("xxxHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 863 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 864 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 865 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 866 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 867 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 868 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 869 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 870 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 871 | } |
| 872 | |
| 873 | // Allow up to 4 bytes of junk to precede status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 874 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 875 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 876 | MockRead("\n\nQJHTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 877 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 878 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 879 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 880 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 881 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 882 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 883 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 884 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 885 | } |
| 886 | |
| 887 | // Beyond 4 bytes of slop and it should fail to find a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 888 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk5Bytes) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 889 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 890 | MockRead("xxxxxHTTP/1.1 404 Not Found\nServer: blah"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 891 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 892 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 893 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 894 | EXPECT_THAT(out.rv, IsOk()); |
| 895 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 896 | EXPECT_EQ("xxxxxHTTP/1.1 404 Not Found\nServer: blah", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 897 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 898 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 899 | } |
| 900 | |
| 901 | // Same as StatusLineJunk4Bytes, except the read chunks are smaller. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 902 | TEST_F(HttpNetworkTransactionTest, StatusLineJunk4Bytes_Slow) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 903 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 904 | MockRead("\n"), |
| 905 | MockRead("\n"), |
| 906 | MockRead("Q"), |
| 907 | MockRead("J"), |
| 908 | MockRead("HTTP/1.0 404 Not Found\nServer: blah\n\nDATA"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 909 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 910 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 911 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 912 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 913 | EXPECT_EQ("HTTP/1.0 404 Not Found", out.status_line); |
| 914 | EXPECT_EQ("DATA", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 915 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 916 | EXPECT_EQ(reads_size, out.total_received_bytes); |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 917 | } |
| 918 | |
| 919 | // Close the connection before enough bytes to have a status line. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 920 | TEST_F(HttpNetworkTransactionTest, StatusLinePartial) { |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 921 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 922 | MockRead("HTT"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 923 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 231d5a3 | 2008-09-13 00:45:27 | [diff] [blame] | 924 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 925 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 926 | EXPECT_THAT(out.rv, IsOk()); |
| 927 | EXPECT_EQ("HTTP/0.9 200 OK", out.status_line); |
| 928 | EXPECT_EQ("HTT", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 929 | int64_t reads_size = CountReadBytes(data_reads); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 930 | EXPECT_EQ(reads_size, out.total_received_bytes); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 931 | } |
| 932 | |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 933 | // Simulate a 204 response, lacking a Content-Length header, sent over a |
| 934 | // persistent connection. The response should still terminate since a 204 |
| 935 | // cannot have a response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 936 | TEST_F(HttpNetworkTransactionTest, StopsReading204) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 937 | char junk[] = "junk"; |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 938 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 939 | MockRead("HTTP/1.1 204 No Content\r\n\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 940 | MockRead(junk), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 941 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 942 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 943 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 944 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 945 | EXPECT_EQ("HTTP/1.1 204 No Content", out.status_line); |
| 946 | EXPECT_EQ("", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 947 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 948 | int64_t response_size = reads_size - strlen(junk); |
| 949 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | f9d44aa | 2008-09-23 23:57:17 | [diff] [blame] | 950 | } |
| 951 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 952 | // A simple request using chunked encoding with some extra data after. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 953 | TEST_F(HttpNetworkTransactionTest, ChunkedEncoding) { |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 954 | std::string final_chunk = "0\r\n\r\n"; |
| 955 | std::string extra_data = "HTTP/1.1 200 OK\r\n"; |
| 956 | std::string last_read = final_chunk + extra_data; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 957 | MockRead data_reads[] = { |
| 958 | MockRead("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"), |
| 959 | MockRead("5\r\nHello\r\n"), |
| 960 | MockRead("1\r\n"), |
| 961 | MockRead(" \r\n"), |
| 962 | MockRead("5\r\nworld\r\n"), |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 963 | MockRead(last_read.data()), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 964 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 965 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 966 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 967 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 968 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 969 | EXPECT_EQ("Hello world", out.response_data); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 970 | int64_t reads_size = CountReadBytes(data_reads); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 971 | int64_t response_size = reads_size - extra_data.size(); |
| 972 | EXPECT_EQ(response_size, out.total_received_bytes); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 973 | } |
| 974 | |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 975 | // Next tests deal with http://crbug.com/56344. |
| 976 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 977 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 978 | MultipleContentLengthHeadersNoTransferEncoding) { |
| 979 | MockRead data_reads[] = { |
| 980 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 981 | MockRead("Content-Length: 10\r\n"), |
| 982 | MockRead("Content-Length: 5\r\n\r\n"), |
| 983 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 984 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 985 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 986 | } |
| 987 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 988 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 989 | DuplicateContentLengthHeadersNoTransferEncoding) { |
| 990 | MockRead data_reads[] = { |
| 991 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 992 | MockRead("Content-Length: 5\r\n"), |
| 993 | MockRead("Content-Length: 5\r\n\r\n"), |
| 994 | MockRead("Hello"), |
| 995 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 996 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 997 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 998 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 999 | EXPECT_EQ("Hello", out.response_data); |
| 1000 | } |
| 1001 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1002 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1003 | ComplexContentLengthHeadersNoTransferEncoding) { |
| 1004 | // More than 2 dupes. |
| 1005 | { |
| 1006 | MockRead data_reads[] = { |
| 1007 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1008 | MockRead("Content-Length: 5\r\n"), |
| 1009 | MockRead("Content-Length: 5\r\n"), |
| 1010 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1011 | MockRead("Hello"), |
| 1012 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1013 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1014 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1015 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1016 | EXPECT_EQ("Hello", out.response_data); |
| 1017 | } |
| 1018 | // HTTP/1.0 |
| 1019 | { |
| 1020 | MockRead data_reads[] = { |
| 1021 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1022 | MockRead("Content-Length: 5\r\n"), |
| 1023 | MockRead("Content-Length: 5\r\n"), |
| 1024 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1025 | MockRead("Hello"), |
| 1026 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1027 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1028 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1029 | EXPECT_EQ("HTTP/1.0 200 OK", out.status_line); |
| 1030 | EXPECT_EQ("Hello", out.response_data); |
| 1031 | } |
| 1032 | // 2 dupes and one mismatched. |
| 1033 | { |
| 1034 | MockRead data_reads[] = { |
| 1035 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1036 | MockRead("Content-Length: 10\r\n"), |
| 1037 | MockRead("Content-Length: 10\r\n"), |
| 1038 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1039 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1040 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1041 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_LENGTH)); |
[email protected] | 44b5204 | 2010-10-29 22:48:04 | [diff] [blame] | 1042 | } |
| 1043 | } |
| 1044 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1045 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1046 | MultipleContentLengthHeadersTransferEncoding) { |
| 1047 | MockRead data_reads[] = { |
| 1048 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1049 | MockRead("Content-Length: 666\r\n"), |
| 1050 | MockRead("Content-Length: 1337\r\n"), |
| 1051 | MockRead("Transfer-Encoding: chunked\r\n\r\n"), |
| 1052 | MockRead("5\r\nHello\r\n"), |
| 1053 | MockRead("1\r\n"), |
| 1054 | MockRead(" \r\n"), |
| 1055 | MockRead("5\r\nworld\r\n"), |
| 1056 | MockRead("0\r\n\r\nHTTP/1.1 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1057 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1058 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1059 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1060 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 9fe44f5 | 2010-09-23 18:36:00 | [diff] [blame] | 1061 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1062 | EXPECT_EQ("Hello world", out.response_data); |
| 1063 | } |
| 1064 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1065 | // Next tests deal with http://crbug.com/98895. |
| 1066 | |
| 1067 | // Checks that a single Content-Disposition header results in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1068 | TEST_F(HttpNetworkTransactionTest, SingleContentDispositionHeader) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1069 | MockRead data_reads[] = { |
| 1070 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1071 | MockRead("Content-Disposition: attachment;filename=\"salutations.txt\"r\n"), |
| 1072 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1073 | MockRead("Hello"), |
| 1074 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1075 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1076 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1077 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1078 | EXPECT_EQ("Hello", out.response_data); |
| 1079 | } |
| 1080 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1081 | // Checks that two identical Content-Disposition headers result in no error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1082 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1083 | MockRead data_reads[] = { |
| 1084 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1085 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1086 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1087 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1088 | MockRead("Hello"), |
| 1089 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1090 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1091 | EXPECT_THAT(out.rv, IsOk()); |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1092 | EXPECT_EQ("HTTP/1.1 200 OK", out.status_line); |
| 1093 | EXPECT_EQ("Hello", out.response_data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1094 | } |
| 1095 | |
| 1096 | // Checks that two distinct Content-Disposition headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1097 | TEST_F(HttpNetworkTransactionTest, TwoDistinctContentDispositionHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1098 | MockRead data_reads[] = { |
| 1099 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 1100 | MockRead("Content-Disposition: attachment;filename=\"greetings.txt\"r\n"), |
| 1101 | MockRead("Content-Disposition: attachment;filename=\"hi.txt\"r\n"), |
| 1102 | MockRead("Content-Length: 5\r\n\r\n"), |
| 1103 | MockRead("Hello"), |
| 1104 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1105 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1106 | EXPECT_THAT(out.rv, |
| 1107 | IsError(ERR_RESPONSE_HEADERS_MULTIPLE_CONTENT_DISPOSITION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1108 | } |
| 1109 | |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1110 | // Checks that two identical Location headers result in no error. |
| 1111 | // Also tests Location header behavior. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1112 | TEST_F(HttpNetworkTransactionTest, TwoIdenticalLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1113 | MockRead data_reads[] = { |
| 1114 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1115 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 54a9c6e5 | 2012-03-21 20:10:59 | [diff] [blame] | 1116 | MockRead("Location: http://good.com/\r\n"), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1117 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1118 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1119 | }; |
| 1120 | |
| 1121 | HttpRequestInfo request; |
| 1122 | request.method = "GET"; |
| 1123 | request.url = GURL("http://redirect.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1124 | request.traffic_annotation = |
| 1125 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1126 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1127 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1128 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1129 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1130 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1131 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1132 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1133 | TestCompletionCallback callback; |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1134 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1135 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1136 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1137 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1138 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1139 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1140 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1141 | ASSERT_TRUE(response); |
| 1142 | ASSERT_TRUE(response->headers); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1143 | EXPECT_EQ("HTTP/1.1 302 Redirect", response->headers->GetStatusLine()); |
| 1144 | std::string url; |
| 1145 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 1146 | EXPECT_EQ("http://good.com/", url); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1147 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1148 | } |
| 1149 | |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1150 | // Checks that two distinct Location headers result in an error. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1151 | TEST_F(HttpNetworkTransactionTest, TwoDistinctLocationHeaders) { |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1152 | MockRead data_reads[] = { |
| 1153 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 1154 | MockRead("Location: http://good.com/\r\n"), |
| 1155 | MockRead("Location: http://evil.com/\r\n"), |
| 1156 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1157 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1158 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1159 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1160 | EXPECT_THAT(out.rv, IsError(ERR_RESPONSE_HEADERS_MULTIPLE_LOCATION)); |
[email protected] | 1628fe9 | 2011-10-04 23:04:55 | [diff] [blame] | 1161 | } |
| 1162 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1163 | // Do a request using the HEAD method. Verify that we don't try to read the |
| 1164 | // message body (since HEAD has none). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1165 | TEST_F(HttpNetworkTransactionTest, Head) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1166 | HttpRequestInfo request; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1167 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1168 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1169 | request.traffic_annotation = |
| 1170 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1171 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1172 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1173 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1174 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1175 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1176 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 1177 | base::Unretained(&headers_handler))); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1178 | |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1179 | MockWrite data_writes1[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 1180 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 1181 | "Host: www.example.org\r\n" |
| 1182 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1183 | }; |
| 1184 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1185 | MockRead("HTTP/1.1 404 Not Found\r\n"), MockRead("Server: Blah\r\n"), |
| 1186 | MockRead("Content-Length: 1234\r\n\r\n"), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1187 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 1188 | // No response body because the test stops reading here. |
| 1189 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1190 | }; |
| 1191 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1192 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1193 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1194 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1195 | TestCompletionCallback callback1; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1196 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1197 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1198 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1199 | |
| 1200 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1201 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1202 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1203 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1204 | ASSERT_TRUE(response); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1205 | |
| 1206 | // Check that the headers got parsed. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1207 | EXPECT_TRUE(response->headers); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1208 | EXPECT_EQ(1234, response->headers->GetContentLength()); |
| 1209 | EXPECT_EQ("HTTP/1.1 404 Not Found", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1210 | EXPECT_TRUE(response->proxy_server.is_direct()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 1211 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 1212 | EXPECT_FALSE(headers_handler.observed_before_headers_sent_with_proxy()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1213 | |
| 1214 | std::string server_header; |
olli.raula | ee489a5 | 2016-01-25 08:37:10 | [diff] [blame] | 1215 | size_t iter = 0; |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1216 | bool has_server_header = response->headers->EnumerateHeader( |
| 1217 | &iter, "Server", &server_header); |
| 1218 | EXPECT_TRUE(has_server_header); |
| 1219 | EXPECT_EQ("Blah", server_header); |
| 1220 | |
| 1221 | // Reading should give EOF right away, since there is no message body |
| 1222 | // (despite non-zero content-length). |
| 1223 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1224 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1225 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ef0faf2e7 | 2009-03-05 23:27:23 | [diff] [blame] | 1226 | EXPECT_EQ("", response_data); |
| 1227 | } |
| 1228 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1229 | TEST_F(HttpNetworkTransactionTest, ReuseConnection) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1230 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1231 | |
| 1232 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1233 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1234 | MockRead("hello"), |
| 1235 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1236 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1237 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1238 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1239 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1240 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1241 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1242 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1243 | "hello", "world" |
| 1244 | }; |
| 1245 | |
| 1246 | for (int i = 0; i < 2; ++i) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1247 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1248 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1249 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1250 | request.traffic_annotation = |
| 1251 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1252 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1253 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1254 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1255 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1256 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1257 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1258 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1259 | |
| 1260 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1261 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1262 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1263 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1264 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1265 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1266 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1267 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1268 | EXPECT_TRUE(response->proxy_server.is_direct()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1269 | |
| 1270 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1271 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1272 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1273 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1274 | } |
| 1275 | } |
| 1276 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1277 | TEST_F(HttpNetworkTransactionTest, Ignores100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1278 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1279 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1280 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 1281 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1282 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1283 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1284 | request.method = "POST"; |
| 1285 | request.url = GURL("http://www.foo.com/"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 1286 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1287 | request.traffic_annotation = |
| 1288 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1289 | |
shivanisha | b9a14395 | 2016-09-19 17:23:41 | [diff] [blame] | 1290 | // Check the upload progress returned before initialization is correct. |
| 1291 | UploadProgress progress = request.upload_data_stream->GetUploadProgress(); |
| 1292 | EXPECT_EQ(0u, progress.size()); |
| 1293 | EXPECT_EQ(0u, progress.position()); |
| 1294 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1295 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1296 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1297 | |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1298 | MockRead data_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1299 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 1300 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 1301 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1302 | MockRead(SYNCHRONOUS, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1303 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1304 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1305 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1306 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1307 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1308 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1309 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1310 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1311 | |
| 1312 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1313 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1314 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1315 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1316 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1317 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1318 | EXPECT_TRUE(response->headers); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1319 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1320 | |
| 1321 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1322 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1323 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1324 | EXPECT_EQ("hello world", response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1325 | } |
| 1326 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1327 | // This test is almost the same as Ignores100 above, but the response contains |
| 1328 | // 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] | 1329 | // HTTP/1.1 and the two status headers are read in one read. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1330 | TEST_F(HttpNetworkTransactionTest, Ignores1xx) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1331 | HttpRequestInfo request; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1332 | request.method = "GET"; |
| 1333 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1334 | request.traffic_annotation = |
| 1335 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1336 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1337 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1338 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1339 | |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1340 | MockRead data_reads[] = { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 1341 | MockRead("HTTP/1.1 102 Unspecified status code\r\n\r\n" |
| 1342 | "HTTP/1.1 200 OK\r\n\r\n"), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1343 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1344 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1345 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1346 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1347 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1348 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1349 | TestCompletionCallback callback; |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1350 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1351 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1352 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1353 | |
| 1354 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1355 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1356 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1357 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1358 | ASSERT_TRUE(response); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1359 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1360 | EXPECT_TRUE(response->headers); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1361 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1362 | |
| 1363 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1364 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1365 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3a2d366 | 2009-03-27 03:49:14 | [diff] [blame] | 1366 | EXPECT_EQ("hello world", response_data); |
| 1367 | } |
| 1368 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1369 | TEST_F(HttpNetworkTransactionTest, Incomplete100ThenEOF) { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1370 | HttpRequestInfo request; |
| 1371 | request.method = "POST"; |
| 1372 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1373 | request.traffic_annotation = |
| 1374 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1375 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1376 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1377 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1378 | |
| 1379 | MockRead data_reads[] = { |
| 1380 | MockRead(SYNCHRONOUS, "HTTP/1.0 100 Continue\r\n"), |
| 1381 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1382 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1383 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1384 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1385 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1386 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1387 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1388 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1389 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1390 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1391 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1392 | EXPECT_THAT(rv, IsOk()); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1393 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1394 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1395 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1396 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 1397 | EXPECT_EQ("", response_data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1398 | } |
| 1399 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1400 | TEST_F(HttpNetworkTransactionTest, EmptyResponse) { |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1401 | HttpRequestInfo request; |
| 1402 | request.method = "POST"; |
| 1403 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1404 | request.traffic_annotation = |
| 1405 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1406 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1407 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1408 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1409 | |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1410 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1411 | MockRead(ASYNC, 0), |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1412 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1413 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1414 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1415 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1416 | TestCompletionCallback callback; |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1417 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1418 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1419 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1420 | |
| 1421 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1422 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | ee9410e7 | 2010-01-07 01:42:38 | [diff] [blame] | 1423 | } |
| 1424 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 1425 | void HttpNetworkTransactionTest::KeepAliveConnectionResendRequestTest( |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1426 | const MockWrite* write_failure, |
| 1427 | const MockRead* read_failure) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1428 | HttpRequestInfo request; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1429 | request.method = "GET"; |
| 1430 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1431 | request.traffic_annotation = |
| 1432 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1433 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1434 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1435 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1436 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1437 | |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1438 | // Written data for successfully sending both requests. |
| 1439 | MockWrite data1_writes[] = { |
| 1440 | MockWrite("GET / HTTP/1.1\r\n" |
| 1441 | "Host: www.foo.com\r\n" |
| 1442 | "Connection: keep-alive\r\n\r\n"), |
| 1443 | MockWrite("GET / HTTP/1.1\r\n" |
| 1444 | "Host: www.foo.com\r\n" |
| 1445 | "Connection: keep-alive\r\n\r\n") |
| 1446 | }; |
| 1447 | |
| 1448 | // Read results for the first request. |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1449 | MockRead data1_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1450 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1451 | MockRead("hello"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1452 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1453 | }; |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1454 | |
| 1455 | if (write_failure) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1456 | ASSERT_FALSE(read_failure); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1457 | data1_writes[1] = *write_failure; |
| 1458 | } else { |
| 1459 | ASSERT_TRUE(read_failure); |
| 1460 | data1_reads[2] = *read_failure; |
| 1461 | } |
| 1462 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1463 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1464 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1465 | |
| 1466 | MockRead data2_reads[] = { |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1467 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 1468 | MockRead("world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1469 | MockRead(ASYNC, OK), |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1470 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1471 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1472 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1473 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 1474 | const char* const kExpectedResponseData[] = { |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1475 | "hello", "world" |
| 1476 | }; |
| 1477 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 1478 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1479 | for (int i = 0; i < 2; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1480 | TestCompletionCallback callback; |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1481 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1482 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1483 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1484 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1485 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1486 | |
| 1487 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1488 | EXPECT_THAT(rv, IsOk()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1489 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1490 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1491 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 1492 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 1493 | if (i == 0) { |
| 1494 | first_socket_log_id = load_timing_info.socket_log_id; |
| 1495 | } else { |
| 1496 | // The second request should be using a new socket. |
| 1497 | EXPECT_NE(first_socket_log_id, load_timing_info.socket_log_id); |
| 1498 | } |
| 1499 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1500 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1501 | ASSERT_TRUE(response); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1502 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1503 | EXPECT_TRUE(response->headers); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 1504 | EXPECT_TRUE(response->proxy_server.is_direct()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1505 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1506 | |
| 1507 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1508 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1509 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1510 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
initial.commit | 586acc5fe | 2008-07-26 22:42:52 | [diff] [blame] | 1511 | } |
| 1512 | } |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1513 | |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1514 | void HttpNetworkTransactionTest::PreconnectErrorResendRequestTest( |
| 1515 | const MockWrite* write_failure, |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1516 | const MockRead* read_failure, |
| 1517 | bool use_spdy) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1518 | HttpRequestInfo request; |
| 1519 | request.method = "GET"; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1520 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1521 | request.traffic_annotation = |
| 1522 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1523 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1524 | TestNetLog net_log; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1525 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1526 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1527 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1528 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 1529 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 1530 | if (use_spdy) { |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 1531 | ssl1.next_proto = kProtoHTTP2; |
| 1532 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1533 | } |
| 1534 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 1535 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1536 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1537 | // SPDY versions of the request and response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1538 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 1539 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1540 | spdy::SpdySerializedFrame spdy_response( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 1541 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1542 | spdy::SpdySerializedFrame spdy_data( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 1543 | spdy_util_.ConstructSpdyDataFrame(1, "hello", true)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1544 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1545 | // HTTP/1.1 versions of the request and response. |
| 1546 | const char kHttpRequest[] = "GET / HTTP/1.1\r\n" |
| 1547 | "Host: www.foo.com\r\n" |
| 1548 | "Connection: keep-alive\r\n\r\n"; |
| 1549 | const char kHttpResponse[] = "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"; |
| 1550 | const char kHttpData[] = "hello"; |
| 1551 | |
| 1552 | std::vector<MockRead> data1_reads; |
| 1553 | std::vector<MockWrite> data1_writes; |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1554 | if (write_failure) { |
| 1555 | ASSERT_FALSE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1556 | data1_writes.push_back(*write_failure); |
| 1557 | data1_reads.push_back(MockRead(ASYNC, OK)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1558 | } else { |
| 1559 | ASSERT_TRUE(read_failure); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1560 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1561 | data1_writes.push_back(CreateMockWrite(spdy_request)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1562 | } else { |
| 1563 | data1_writes.push_back(MockWrite(kHttpRequest)); |
| 1564 | } |
| 1565 | data1_reads.push_back(*read_failure); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1566 | } |
| 1567 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1568 | StaticSocketDataProvider data1(data1_reads, data1_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1569 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1570 | |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1571 | std::vector<MockRead> data2_reads; |
| 1572 | std::vector<MockWrite> data2_writes; |
| 1573 | |
| 1574 | if (use_spdy) { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1575 | data2_writes.push_back(CreateMockWrite(spdy_request, 0, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1576 | |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 1577 | data2_reads.push_back(CreateMockRead(spdy_response, 1, ASYNC)); |
| 1578 | data2_reads.push_back(CreateMockRead(spdy_data, 2, ASYNC)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1579 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1580 | } else { |
| 1581 | data2_writes.push_back( |
| 1582 | MockWrite(ASYNC, kHttpRequest, strlen(kHttpRequest), 0)); |
| 1583 | |
| 1584 | data2_reads.push_back( |
| 1585 | MockRead(ASYNC, kHttpResponse, strlen(kHttpResponse), 1)); |
| 1586 | data2_reads.push_back(MockRead(ASYNC, kHttpData, strlen(kHttpData), 2)); |
| 1587 | data2_reads.push_back(MockRead(ASYNC, OK, 3)); |
| 1588 | } |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1589 | SequencedSocketData data2(data2_reads, data2_writes); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1590 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1591 | |
| 1592 | // Preconnect a socket. |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 1593 | session->http_stream_factory()->PreconnectStreams(1, request); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1594 | // Wait for the preconnect to complete. |
| 1595 | // TODO(davidben): Some way to wait for an idle socket count might be handy. |
| 1596 | base::RunLoop().RunUntilIdle(); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1597 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1598 | |
| 1599 | // Make the request. |
| 1600 | TestCompletionCallback callback; |
| 1601 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1602 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1603 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1604 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1605 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1606 | |
| 1607 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1608 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1609 | |
| 1610 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1611 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1612 | TestLoadTimingNotReused( |
| 1613 | load_timing_info, |
| 1614 | CONNECT_TIMING_HAS_DNS_TIMES|CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1615 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1616 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1617 | ASSERT_TRUE(response); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1618 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 1619 | EXPECT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 1620 | if (response->was_fetched_via_spdy) { |
| 1621 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 1622 | } else { |
| 1623 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 1624 | } |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1625 | |
| 1626 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1627 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1628 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1629 | EXPECT_EQ(kHttpData, response_data); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1630 | } |
| 1631 | |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1632 | // Test that we do not retry indefinitely when a server sends an error like |
| 1633 | // ERR_SPDY_PING_FAILED, ERR_SPDY_SERVER_REFUSED_STREAM, |
| 1634 | // ERR_QUIC_HANDSHAKE_FAILED or ERR_QUIC_PROTOCOL_ERROR. |
| 1635 | TEST_F(HttpNetworkTransactionTest, FiniteRetriesOnIOError) { |
| 1636 | HttpRequestInfo request; |
| 1637 | request.method = "GET"; |
| 1638 | request.url = GURL("https://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); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1641 | |
| 1642 | // Check whether we give up after the third try. |
| 1643 | |
| 1644 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1645 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1646 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1647 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1648 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1649 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1650 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1651 | |
| 1652 | // Three go away responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1653 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1654 | StaticSocketDataProvider data2(data_read1, data_write); |
| 1655 | StaticSocketDataProvider data3(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1656 | |
| 1657 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1658 | AddSSLSocketData(); |
| 1659 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1660 | AddSSLSocketData(); |
| 1661 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1662 | AddSSLSocketData(); |
| 1663 | |
| 1664 | TestCompletionCallback callback; |
| 1665 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1666 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1667 | |
| 1668 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1669 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1670 | |
| 1671 | rv = callback.WaitForResult(); |
| 1672 | EXPECT_THAT(rv, IsError(ERR_SPDY_SERVER_REFUSED_STREAM)); |
| 1673 | } |
| 1674 | |
| 1675 | TEST_F(HttpNetworkTransactionTest, RetryTwiceOnIOError) { |
| 1676 | HttpRequestInfo request; |
| 1677 | request.method = "GET"; |
| 1678 | request.url = GURL("https://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1679 | request.traffic_annotation = |
| 1680 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1681 | |
| 1682 | // Check whether we try atleast thrice before giving up. |
| 1683 | |
| 1684 | // Construct an HTTP2 request and a "Go away" response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1685 | spdy::SpdySerializedFrame spdy_request(spdy_util_.ConstructSpdyGet( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1686 | request.url.spec().c_str(), 1, DEFAULT_PRIORITY)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1687 | spdy::SpdySerializedFrame spdy_response_go_away( |
| 1688 | spdy_util_.ConstructSpdyGoAway(0)); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1689 | MockRead data_read1[] = {CreateMockRead(spdy_response_go_away)}; |
| 1690 | MockWrite data_write[] = {CreateMockWrite(spdy_request, 0)}; |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1691 | |
| 1692 | // Construct a non error HTTP2 response. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1693 | spdy::SpdySerializedFrame spdy_response_no_error( |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1694 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 1695 | spdy::SpdySerializedFrame spdy_data( |
| 1696 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1697 | MockRead data_read2[] = {CreateMockRead(spdy_response_no_error, 1), |
| 1698 | CreateMockRead(spdy_data, 2)}; |
| 1699 | |
| 1700 | // Two error responses. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1701 | StaticSocketDataProvider data1(data_read1, data_write); |
| 1702 | StaticSocketDataProvider data2(data_read1, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1703 | // Followed by a success response. |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1704 | SequencedSocketData data3(data_read2, data_write); |
Biljith Jayan | 45a4172 | 2017-08-16 18:43:14 | [diff] [blame] | 1705 | |
| 1706 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 1707 | AddSSLSocketData(); |
| 1708 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 1709 | AddSSLSocketData(); |
| 1710 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 1711 | AddSSLSocketData(); |
| 1712 | |
| 1713 | TestCompletionCallback callback; |
| 1714 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 1715 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 1716 | |
| 1717 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 1718 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 1719 | |
| 1720 | rv = callback.WaitForResult(); |
| 1721 | EXPECT_THAT(rv, IsOk()); |
| 1722 | } |
| 1723 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1724 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionNotConnectedOnWrite) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1725 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1726 | KeepAliveConnectionResendRequestTest(&write_failure, NULL); |
| 1727 | } |
| 1728 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1729 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionReset) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1730 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1731 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1732 | } |
| 1733 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1734 | TEST_F(HttpNetworkTransactionTest, KeepAliveConnectionEOF) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1735 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 20296599 | 2011-12-07 23:04:51 | [diff] [blame] | 1736 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1737 | } |
| 1738 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1739 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1740 | // if the socket was a reused keep alive socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1741 | TEST_F(HttpNetworkTransactionTest, KeepAlive408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1742 | MockRead read_failure(SYNCHRONOUS, |
| 1743 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1744 | "Connection: Keep-Alive\r\n" |
| 1745 | "Content-Length: 6\r\n\r\n" |
| 1746 | "Pickle"); |
| 1747 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1748 | } |
| 1749 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1750 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorNotConnectedOnWrite) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1751 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1752 | PreconnectErrorResendRequestTest(&write_failure, NULL, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1753 | } |
| 1754 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1755 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorReset) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1756 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1757 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1758 | } |
| 1759 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1760 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorEOF) { |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1761 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1762 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1763 | } |
| 1764 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1765 | TEST_F(HttpNetworkTransactionTest, PreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1766 | MockRead read_failure(ASYNC, OK); // EOF |
| 1767 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1768 | } |
| 1769 | |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1770 | // Make sure that on a 408 response (Request Timeout), the request is retried, |
| 1771 | // if the socket was a preconnected (UNUSED_IDLE) socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1772 | TEST_F(HttpNetworkTransactionTest, RetryOnIdle408) { |
[email protected] | d58ceea8 | 2014-06-04 10:55:54 | [diff] [blame] | 1773 | MockRead read_failure(SYNCHRONOUS, |
| 1774 | "HTTP/1.1 408 Request Timeout\r\n" |
| 1775 | "Connection: Keep-Alive\r\n" |
| 1776 | "Content-Length: 6\r\n\r\n" |
| 1777 | "Pickle"); |
| 1778 | KeepAliveConnectionResendRequestTest(NULL, &read_failure); |
| 1779 | PreconnectErrorResendRequestTest(NULL, &read_failure, false); |
| 1780 | } |
| 1781 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1782 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorNotConnectedOnWrite) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1783 | MockWrite write_failure(ASYNC, ERR_SOCKET_NOT_CONNECTED); |
| 1784 | PreconnectErrorResendRequestTest(&write_failure, NULL, true); |
| 1785 | } |
| 1786 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1787 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorReset) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1788 | MockRead read_failure(ASYNC, ERR_CONNECTION_RESET); |
| 1789 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1790 | } |
| 1791 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1792 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1793 | MockRead read_failure(SYNCHRONOUS, OK); // EOF |
| 1794 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
| 1795 | } |
| 1796 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1797 | TEST_F(HttpNetworkTransactionTest, SpdyPreconnectErrorAsyncEOF) { |
[email protected] | 09356c65 | 2014-03-25 15:36:10 | [diff] [blame] | 1798 | MockRead read_failure(ASYNC, OK); // EOF |
| 1799 | PreconnectErrorResendRequestTest(NULL, &read_failure, true); |
[email protected] | a34f61ee | 2014-03-18 20:59:49 | [diff] [blame] | 1800 | } |
| 1801 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1802 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionReset) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1803 | HttpRequestInfo request; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1804 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1805 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1806 | request.traffic_annotation = |
| 1807 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1808 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1809 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1810 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1811 | |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1812 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1813 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1814 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1815 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1816 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1817 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1818 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1819 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1820 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 1821 | TestCompletionCallback callback; |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1822 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1823 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1824 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1825 | |
| 1826 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1827 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1828 | |
| 1829 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 1830 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 1831 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | // What do various browsers do when the server closes a non-keepalive |
| 1835 | // connection without sending any response header or body? |
| 1836 | // |
| 1837 | // IE7: error page |
| 1838 | // Safari 3.1.2 (Windows): error page |
| 1839 | // Firefox 3.0.1: blank page |
| 1840 | // Opera 9.52: after five attempts, blank page |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 1841 | // Us with WinHTTP: error page (ERR_INVALID_RESPONSE) |
| 1842 | // Us: error page (EMPTY_RESPONSE) |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1843 | TEST_F(HttpNetworkTransactionTest, NonKeepAliveConnectionEOF) { |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1844 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1845 | MockRead(SYNCHRONOUS, OK), // EOF |
[email protected] | 217e602 | 2008-09-29 18:18:35 | [diff] [blame] | 1846 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), // Should not be used |
| 1847 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 1848 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1849 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1850 | SimpleGetHelperResult out = SimpleGetHelper(data_reads); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1851 | EXPECT_THAT(out.rv, IsError(ERR_EMPTY_RESPONSE)); |
[email protected] | 3d2a59b | 2008-09-26 19:44:25 | [diff] [blame] | 1852 | } |
[email protected] | 1826a40 | 2014-01-08 15:40:48 | [diff] [blame] | 1853 | |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1854 | // Next 2 cases (KeepAliveEarlyClose and KeepAliveEarlyClose2) are regression |
| 1855 | // tests. There was a bug causing HttpNetworkTransaction to hang in the |
| 1856 | // destructor in such situations. |
| 1857 | // See http://crbug.com/154712 and http://crbug.com/156609. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1858 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1859 | HttpRequestInfo request; |
| 1860 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1861 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1862 | request.traffic_annotation = |
| 1863 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1864 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1865 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1866 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1867 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1868 | |
| 1869 | MockRead data_reads[] = { |
| 1870 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1871 | MockRead("Connection: keep-alive\r\n"), |
| 1872 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1873 | MockRead("hello"), |
| 1874 | MockRead(SYNCHRONOUS, 0), |
| 1875 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1876 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1877 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1878 | |
| 1879 | TestCompletionCallback callback; |
| 1880 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1881 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1882 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1883 | |
| 1884 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1885 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1886 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 1887 | scoped_refptr<IOBufferWithSize> io_buf = |
| 1888 | base::MakeRefCounted<IOBufferWithSize>(100); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1889 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1890 | if (rv == ERR_IO_PENDING) |
| 1891 | rv = callback.WaitForResult(); |
| 1892 | EXPECT_EQ(5, rv); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1893 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1894 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1895 | |
| 1896 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1897 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1898 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1899 | } |
| 1900 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1901 | TEST_F(HttpNetworkTransactionTest, KeepAliveEarlyClose2) { |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1902 | HttpRequestInfo request; |
| 1903 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 1904 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1905 | request.traffic_annotation = |
| 1906 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1907 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1908 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 1909 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 1910 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1911 | |
| 1912 | MockRead data_reads[] = { |
| 1913 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 1914 | MockRead("Connection: keep-alive\r\n"), |
| 1915 | MockRead("Content-Length: 100\r\n\r\n"), |
| 1916 | MockRead(SYNCHRONOUS, 0), |
| 1917 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 1918 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1919 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1920 | |
| 1921 | TestCompletionCallback callback; |
| 1922 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 1923 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1924 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1925 | |
| 1926 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1927 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1928 | |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 1929 | scoped_refptr<IOBufferWithSize> io_buf( |
| 1930 | base::MakeRefCounted<IOBufferWithSize>(100)); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 1931 | rv = trans->Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1932 | if (rv == ERR_IO_PENDING) |
| 1933 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 1934 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1935 | |
| 1936 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 1937 | base::RunLoop().RunUntilIdle(); |
[email protected] | 7a5378b | 2012-11-04 03:25:17 | [diff] [blame] | 1938 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 1939 | } |
| 1940 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1941 | // Test that we correctly reuse a keep-alive connection after not explicitly |
| 1942 | // reading the body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 1943 | TEST_F(HttpNetworkTransactionTest, KeepAliveAfterUnreadBody) { |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1944 | HttpRequestInfo request; |
| 1945 | request.method = "GET"; |
| 1946 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 1947 | request.traffic_annotation = |
| 1948 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1949 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 1950 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 1951 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 1952 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 1953 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1954 | const char* request_data = |
| 1955 | "GET / HTTP/1.1\r\n" |
| 1956 | "Host: www.foo.com\r\n" |
| 1957 | "Connection: keep-alive\r\n\r\n"; |
| 1958 | MockWrite data_writes[] = { |
| 1959 | MockWrite(ASYNC, 0, request_data), MockWrite(ASYNC, 2, request_data), |
| 1960 | MockWrite(ASYNC, 4, request_data), MockWrite(ASYNC, 6, request_data), |
| 1961 | MockWrite(ASYNC, 8, request_data), MockWrite(ASYNC, 10, request_data), |
| 1962 | MockWrite(ASYNC, 12, request_data), MockWrite(ASYNC, 14, request_data), |
| 1963 | MockWrite(ASYNC, 17, request_data), MockWrite(ASYNC, 20, request_data), |
| 1964 | }; |
| 1965 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 1966 | // Note that because all these reads happen in the same |
| 1967 | // StaticSocketDataProvider, it shows that the same socket is being reused for |
| 1968 | // all transactions. |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1969 | MockRead data_reads[] = { |
| 1970 | MockRead(ASYNC, 1, "HTTP/1.1 204 No Content\r\n\r\n"), |
| 1971 | MockRead(ASYNC, 3, "HTTP/1.1 205 Reset Content\r\n\r\n"), |
| 1972 | MockRead(ASYNC, 5, "HTTP/1.1 304 Not Modified\r\n\r\n"), |
| 1973 | MockRead(ASYNC, 7, |
| 1974 | "HTTP/1.1 302 Found\r\n" |
| 1975 | "Content-Length: 0\r\n\r\n"), |
| 1976 | MockRead(ASYNC, 9, |
| 1977 | "HTTP/1.1 302 Found\r\n" |
| 1978 | "Content-Length: 5\r\n\r\n" |
| 1979 | "hello"), |
| 1980 | MockRead(ASYNC, 11, |
| 1981 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1982 | "Content-Length: 0\r\n\r\n"), |
| 1983 | MockRead(ASYNC, 13, |
| 1984 | "HTTP/1.1 301 Moved Permanently\r\n" |
| 1985 | "Content-Length: 5\r\n\r\n" |
| 1986 | "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1987 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1988 | // In the next two rounds, IsConnectedAndIdle returns false, due to |
| 1989 | // the set_busy_before_sync_reads(true) call, while the |
| 1990 | // HttpNetworkTransaction is being shut down, but the socket is still |
| 1991 | // reuseable. See http://crbug.com/544255. |
| 1992 | MockRead(ASYNC, 15, |
| 1993 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1994 | "Content-Length: 5\r\n\r\n"), |
| 1995 | MockRead(SYNCHRONOUS, 16, "hello"), |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 1996 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 1997 | MockRead(ASYNC, 18, |
| 1998 | "HTTP/1.1 200 Hunky-Dory\r\n" |
| 1999 | "Content-Length: 5\r\n\r\n" |
| 2000 | "he"), |
| 2001 | MockRead(SYNCHRONOUS, 19, "llo"), |
| 2002 | |
| 2003 | // The body of the final request is actually read. |
| 2004 | MockRead(ASYNC, 21, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 2005 | MockRead(ASYNC, 22, "hello"), |
| 2006 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2007 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2008 | data.set_busy_before_sync_reads(true); |
| 2009 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2010 | |
| 2011 | const int kNumUnreadBodies = arraysize(data_writes) - 1; |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2012 | std::string response_lines[kNumUnreadBodies]; |
| 2013 | |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 2014 | uint32_t first_socket_log_id = NetLogSource::kInvalidId; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2015 | for (size_t i = 0; i < kNumUnreadBodies; ++i) { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2016 | TestCompletionCallback callback; |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2017 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2018 | auto trans = std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2019 | session.get()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2020 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2021 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2022 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2023 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2024 | LoadTimingInfo load_timing_info; |
| 2025 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 2026 | if (i == 0) { |
| 2027 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2028 | first_socket_log_id = load_timing_info.socket_log_id; |
| 2029 | } else { |
| 2030 | TestLoadTimingReused(load_timing_info); |
| 2031 | EXPECT_EQ(first_socket_log_id, load_timing_info.socket_log_id); |
| 2032 | } |
| 2033 | |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2034 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2035 | ASSERT_TRUE(response); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2036 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2037 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2038 | response_lines[i] = response->headers->GetStatusLine(); |
| 2039 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2040 | // Delete the transaction without reading the response bodies. Then spin |
| 2041 | // the message loop, so the response bodies are drained. |
| 2042 | trans.reset(); |
| 2043 | base::RunLoop().RunUntilIdle(); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2044 | } |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2045 | |
| 2046 | const char* const kStatusLines[] = { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2047 | "HTTP/1.1 204 No Content", |
| 2048 | "HTTP/1.1 205 Reset Content", |
| 2049 | "HTTP/1.1 304 Not Modified", |
| 2050 | "HTTP/1.1 302 Found", |
| 2051 | "HTTP/1.1 302 Found", |
| 2052 | "HTTP/1.1 301 Moved Permanently", |
| 2053 | "HTTP/1.1 301 Moved Permanently", |
| 2054 | "HTTP/1.1 200 Hunky-Dory", |
| 2055 | "HTTP/1.1 200 Hunky-Dory", |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2056 | }; |
| 2057 | |
mostynb | 91e0da98 | 2015-01-20 19:17:27 | [diff] [blame] | 2058 | static_assert(kNumUnreadBodies == arraysize(kStatusLines), |
| 2059 | "forgot to update kStatusLines"); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2060 | |
| 2061 | for (int i = 0; i < kNumUnreadBodies; ++i) |
| 2062 | EXPECT_EQ(kStatusLines[i], response_lines[i]); |
| 2063 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2064 | TestCompletionCallback callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2065 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2066 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2067 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2068 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2069 | ASSERT_TRUE(response); |
| 2070 | ASSERT_TRUE(response->headers); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2071 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 2072 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2073 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2074 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2075 | EXPECT_EQ("hello", response_data); |
[email protected] | fc31d6a4 | 2010-06-24 18:05:13 | [diff] [blame] | 2076 | } |
| 2077 | |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2078 | // Sockets that receive extra data after a response is complete should not be |
| 2079 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2080 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData1) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2081 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2082 | MockWrite data_writes1[] = { |
| 2083 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 2084 | "Host: www.borked.com\r\n" |
| 2085 | "Connection: keep-alive\r\n\r\n"), |
| 2086 | }; |
| 2087 | |
| 2088 | MockRead data_reads1[] = { |
| 2089 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2090 | "Connection: keep-alive\r\n" |
| 2091 | "Content-Length: 22\r\n\r\n" |
| 2092 | "This server is borked."), |
| 2093 | }; |
| 2094 | |
| 2095 | MockWrite data_writes2[] = { |
| 2096 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2097 | "Host: www.borked.com\r\n" |
| 2098 | "Connection: keep-alive\r\n\r\n"), |
| 2099 | }; |
| 2100 | |
| 2101 | MockRead data_reads2[] = { |
| 2102 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2103 | "Content-Length: 3\r\n\r\n" |
| 2104 | "foo"), |
| 2105 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2106 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2107 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2108 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2109 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2110 | |
| 2111 | TestCompletionCallback callback; |
| 2112 | HttpRequestInfo request1; |
| 2113 | request1.method = "HEAD"; |
| 2114 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2115 | request1.traffic_annotation = |
| 2116 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2117 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2118 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2119 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2120 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2121 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2122 | |
| 2123 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2124 | ASSERT_TRUE(response1); |
| 2125 | ASSERT_TRUE(response1->headers); |
| 2126 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2127 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2128 | |
| 2129 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2130 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2131 | EXPECT_EQ("", response_data1); |
| 2132 | // Deleting the transaction attempts to release the socket back into the |
| 2133 | // socket pool. |
| 2134 | trans1.reset(); |
| 2135 | |
| 2136 | HttpRequestInfo request2; |
| 2137 | request2.method = "GET"; |
| 2138 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2139 | request2.traffic_annotation = |
| 2140 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2141 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2142 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2143 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2144 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2145 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2146 | |
| 2147 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2148 | ASSERT_TRUE(response2); |
| 2149 | ASSERT_TRUE(response2->headers); |
| 2150 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2151 | |
| 2152 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2153 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2154 | EXPECT_EQ("foo", response_data2); |
| 2155 | } |
| 2156 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2157 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData2) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2158 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2159 | MockWrite data_writes1[] = { |
| 2160 | MockWrite("GET / HTTP/1.1\r\n" |
| 2161 | "Host: www.borked.com\r\n" |
| 2162 | "Connection: keep-alive\r\n\r\n"), |
| 2163 | }; |
| 2164 | |
| 2165 | MockRead data_reads1[] = { |
| 2166 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2167 | "Connection: keep-alive\r\n" |
| 2168 | "Content-Length: 22\r\n\r\n" |
| 2169 | "This server is borked." |
| 2170 | "Bonus data!"), |
| 2171 | }; |
| 2172 | |
| 2173 | MockWrite data_writes2[] = { |
| 2174 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2175 | "Host: www.borked.com\r\n" |
| 2176 | "Connection: keep-alive\r\n\r\n"), |
| 2177 | }; |
| 2178 | |
| 2179 | MockRead data_reads2[] = { |
| 2180 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2181 | "Content-Length: 3\r\n\r\n" |
| 2182 | "foo"), |
| 2183 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2184 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2185 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2186 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2187 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2188 | |
| 2189 | TestCompletionCallback callback; |
| 2190 | HttpRequestInfo request1; |
| 2191 | request1.method = "GET"; |
| 2192 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2193 | request1.traffic_annotation = |
| 2194 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2195 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2196 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2197 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2198 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2199 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2200 | |
| 2201 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2202 | ASSERT_TRUE(response1); |
| 2203 | ASSERT_TRUE(response1->headers); |
| 2204 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2205 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2206 | |
| 2207 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2208 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2209 | EXPECT_EQ("This server is borked.", response_data1); |
| 2210 | // Deleting the transaction attempts to release the socket back into the |
| 2211 | // socket pool. |
| 2212 | trans1.reset(); |
| 2213 | |
| 2214 | HttpRequestInfo request2; |
| 2215 | request2.method = "GET"; |
| 2216 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2217 | request2.traffic_annotation = |
| 2218 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2219 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2220 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2221 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2222 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2223 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2224 | |
| 2225 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2226 | ASSERT_TRUE(response2); |
| 2227 | ASSERT_TRUE(response2->headers); |
| 2228 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2229 | |
| 2230 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2231 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2232 | EXPECT_EQ("foo", response_data2); |
| 2233 | } |
| 2234 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2235 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData3) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2236 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2237 | MockWrite data_writes1[] = { |
| 2238 | MockWrite("GET / HTTP/1.1\r\n" |
| 2239 | "Host: www.borked.com\r\n" |
| 2240 | "Connection: keep-alive\r\n\r\n"), |
| 2241 | }; |
| 2242 | |
| 2243 | MockRead data_reads1[] = { |
| 2244 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2245 | "Connection: keep-alive\r\n" |
| 2246 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2247 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2248 | MockRead("0\r\n\r\nBonus data!"), |
| 2249 | }; |
| 2250 | |
| 2251 | MockWrite data_writes2[] = { |
| 2252 | MockWrite("GET /foo HTTP/1.1\r\n" |
| 2253 | "Host: www.borked.com\r\n" |
| 2254 | "Connection: keep-alive\r\n\r\n"), |
| 2255 | }; |
| 2256 | |
| 2257 | MockRead data_reads2[] = { |
| 2258 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2259 | "Content-Length: 3\r\n\r\n" |
| 2260 | "foo"), |
| 2261 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2262 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2263 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2264 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2265 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2266 | |
| 2267 | TestCompletionCallback callback; |
| 2268 | HttpRequestInfo request1; |
| 2269 | request1.method = "GET"; |
| 2270 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2271 | request1.traffic_annotation = |
| 2272 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2273 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2274 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2275 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2276 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2277 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2278 | |
| 2279 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
| 2280 | ASSERT_TRUE(response1); |
| 2281 | ASSERT_TRUE(response1->headers); |
| 2282 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2283 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2284 | |
| 2285 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2286 | EXPECT_THAT(ReadTransaction(trans1.get(), &response_data1), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2287 | EXPECT_EQ("This server is borked.", response_data1); |
| 2288 | // Deleting the transaction attempts to release the socket back into the |
| 2289 | // socket pool. |
| 2290 | trans1.reset(); |
| 2291 | |
| 2292 | HttpRequestInfo request2; |
| 2293 | request2.method = "GET"; |
| 2294 | request2.url = GURL("http://www.borked.com/foo"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2295 | request2.traffic_annotation = |
| 2296 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2297 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2298 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2299 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2300 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2301 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2302 | |
| 2303 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
| 2304 | ASSERT_TRUE(response2); |
| 2305 | ASSERT_TRUE(response2->headers); |
| 2306 | EXPECT_EQ(200, response2->headers->response_code()); |
| 2307 | |
| 2308 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2309 | EXPECT_THAT(ReadTransaction(trans2.get(), &response_data2), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2310 | EXPECT_EQ("foo", response_data2); |
| 2311 | } |
| 2312 | |
| 2313 | // This is a little different from the others - it tests the case that the |
| 2314 | // HttpStreamParser doesn't know if there's extra data on a socket or not when |
| 2315 | // the HttpNetworkTransaction is torn down, because the response body hasn't |
| 2316 | // been read from yet, but the request goes through the HttpResponseBodyDrainer. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2317 | TEST_F(HttpNetworkTransactionTest, KeepAliveWithUnusedData4) { |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2318 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2319 | MockWrite data_writes1[] = { |
| 2320 | MockWrite("GET / HTTP/1.1\r\n" |
| 2321 | "Host: www.borked.com\r\n" |
| 2322 | "Connection: keep-alive\r\n\r\n"), |
| 2323 | }; |
| 2324 | |
| 2325 | MockRead data_reads1[] = { |
| 2326 | MockRead("HTTP/1.1 200 OK\r\n" |
| 2327 | "Connection: keep-alive\r\n" |
| 2328 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 2329 | MockRead("16\r\nThis server is borked.\r\n"), |
| 2330 | MockRead("0\r\n\r\nBonus data!"), |
| 2331 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2332 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2333 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2334 | |
| 2335 | TestCompletionCallback callback; |
| 2336 | HttpRequestInfo request1; |
| 2337 | request1.method = "GET"; |
| 2338 | request1.url = GURL("http://www.borked.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2339 | request1.traffic_annotation = |
| 2340 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2341 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2342 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 2343 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2344 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2345 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2346 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2347 | const HttpResponseInfo* response1 = trans->GetResponseInfo(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2348 | ASSERT_TRUE(response1); |
| 2349 | ASSERT_TRUE(response1->headers); |
| 2350 | EXPECT_EQ(200, response1->headers->response_code()); |
| 2351 | EXPECT_TRUE(response1->headers->IsKeepAlive()); |
| 2352 | |
| 2353 | // Deleting the transaction creates an HttpResponseBodyDrainer to read the |
| 2354 | // response body. |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 2355 | trans.reset(); |
mmenke | 5f94fda | 2016-06-02 20:54:13 | [diff] [blame] | 2356 | |
| 2357 | // Let the HttpResponseBodyDrainer drain the socket. It should determine the |
| 2358 | // socket can't be reused, rather than returning it to the socket pool. |
| 2359 | base::RunLoop().RunUntilIdle(); |
| 2360 | |
| 2361 | // There should be no idle sockets in the pool. |
| 2362 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 2363 | } |
| 2364 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2365 | // Test the request-challenge-retry sequence for basic auth. |
| 2366 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2367 | TEST_F(HttpNetworkTransactionTest, BasicAuth) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2368 | HttpRequestInfo request; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2369 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2370 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2371 | request.traffic_annotation = |
| 2372 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2373 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 2374 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2375 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2376 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2377 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2378 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2379 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2380 | MockWrite( |
| 2381 | "GET / HTTP/1.1\r\n" |
| 2382 | "Host: www.example.org\r\n" |
| 2383 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 2384 | }; |
| 2385 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2386 | MockRead data_reads1[] = { |
| 2387 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2388 | // Give a couple authenticate options (only the middle one is actually |
| 2389 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 2390 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2391 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2392 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2393 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2394 | // Large content-length -- won't matter, as connection will be reset. |
| 2395 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2396 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2397 | }; |
| 2398 | |
| 2399 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2400 | // be issuing -- the final header line contains the credentials. |
| 2401 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2402 | MockWrite( |
| 2403 | "GET / HTTP/1.1\r\n" |
| 2404 | "Host: www.example.org\r\n" |
| 2405 | "Connection: keep-alive\r\n" |
| 2406 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2407 | }; |
| 2408 | |
| 2409 | // Lastly, the server responds with the actual content. |
| 2410 | MockRead data_reads2[] = { |
| 2411 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2412 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2413 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2414 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2415 | }; |
| 2416 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2417 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2418 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2419 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2420 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2421 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2422 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2423 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2424 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2425 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2426 | |
| 2427 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2428 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2429 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2430 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2431 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2432 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2433 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2434 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2435 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2436 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2437 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2438 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2439 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2440 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2441 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2442 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2443 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2444 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2445 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2446 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2447 | |
| 2448 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2449 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2450 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2451 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2452 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2453 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2454 | // The load timing after restart should have a new socket ID, and times after |
| 2455 | // those of the first load timing. |
| 2456 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2457 | load_timing_info2.connect_timing.connect_start); |
| 2458 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2459 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2460 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2461 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2462 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2463 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2464 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2465 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2466 | ASSERT_TRUE(response); |
| 2467 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2468 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 2469 | } |
| 2470 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2471 | // Test the request-challenge-retry sequence for basic auth. |
| 2472 | // (basic auth is the easiest to mock, because it has no randomness). |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2473 | TEST_F(HttpNetworkTransactionTest, BasicAuthWithAddressChange) { |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2474 | HttpRequestInfo request; |
| 2475 | request.method = "GET"; |
| 2476 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2477 | request.traffic_annotation = |
| 2478 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2479 | |
| 2480 | TestNetLog log; |
| 2481 | MockHostResolver* resolver = new MockHostResolver(); |
| 2482 | session_deps_.net_log = &log; |
| 2483 | session_deps_.host_resolver.reset(resolver); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2484 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2485 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2486 | |
| 2487 | resolver->rules()->ClearRules(); |
| 2488 | resolver->rules()->AddRule("www.example.org", "127.0.0.1"); |
| 2489 | |
| 2490 | MockWrite data_writes1[] = { |
| 2491 | MockWrite("GET / HTTP/1.1\r\n" |
| 2492 | "Host: www.example.org\r\n" |
| 2493 | "Connection: keep-alive\r\n\r\n"), |
| 2494 | }; |
| 2495 | |
| 2496 | MockRead data_reads1[] = { |
| 2497 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2498 | // Give a couple authenticate options (only the middle one is actually |
| 2499 | // supported). |
| 2500 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2501 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2502 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2503 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2504 | // Large content-length -- won't matter, as connection will be reset. |
| 2505 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2506 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2507 | }; |
| 2508 | |
| 2509 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2510 | // be issuing -- the final header line contains the credentials. |
| 2511 | MockWrite data_writes2[] = { |
| 2512 | MockWrite("GET / HTTP/1.1\r\n" |
| 2513 | "Host: www.example.org\r\n" |
| 2514 | "Connection: keep-alive\r\n" |
| 2515 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2516 | }; |
| 2517 | |
| 2518 | // Lastly, the server responds with the actual content. |
| 2519 | MockRead data_reads2[] = { |
| 2520 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 2521 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2522 | MockRead("Content-Length: 100\r\n\r\n"), MockRead(SYNCHRONOUS, OK), |
| 2523 | }; |
| 2524 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2525 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2526 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2527 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2528 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 2529 | |
| 2530 | TestCompletionCallback callback1; |
| 2531 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2532 | EXPECT_EQ(OK, callback1.GetResult(trans.Start(&request, callback1.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2533 | NetLogWithSource()))); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2534 | |
| 2535 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2536 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2537 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2538 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2539 | int64_t writes_size1 = CountWriteBytes(data_writes1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2540 | EXPECT_EQ(writes_size1, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2541 | int64_t reads_size1 = CountReadBytes(data_reads1); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2542 | EXPECT_EQ(reads_size1, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2543 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2544 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2545 | ASSERT_TRUE(response); |
| 2546 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2547 | |
| 2548 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2549 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2550 | ASSERT_FALSE(endpoint.address().empty()); |
| 2551 | EXPECT_EQ("127.0.0.1:80", endpoint.ToString()); |
| 2552 | |
| 2553 | resolver->rules()->ClearRules(); |
| 2554 | resolver->rules()->AddRule("www.example.org", "127.0.0.2"); |
| 2555 | |
| 2556 | TestCompletionCallback callback2; |
| 2557 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2558 | EXPECT_EQ(OK, callback2.GetResult(trans.RestartWithAuth( |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2559 | AuthCredentials(kFoo, kBar), callback2.callback()))); |
| 2560 | |
| 2561 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2562 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2563 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_DNS_TIMES); |
| 2564 | // The load timing after restart should have a new socket ID, and times after |
| 2565 | // those of the first load timing. |
| 2566 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2567 | load_timing_info2.connect_timing.connect_start); |
| 2568 | EXPECT_NE(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 2569 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2570 | int64_t writes_size2 = CountWriteBytes(data_writes2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2571 | EXPECT_EQ(writes_size1 + writes_size2, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2572 | int64_t reads_size2 = CountReadBytes(data_reads2); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2573 | EXPECT_EQ(reads_size1 + reads_size2, trans.GetTotalReceivedBytes()); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2574 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2575 | response = trans.GetResponseInfo(); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2576 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2577 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2578 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 2579 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2580 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 2581 | ASSERT_FALSE(endpoint.address().empty()); |
| 2582 | EXPECT_EQ("127.0.0.2:80", endpoint.ToString()); |
| 2583 | } |
| 2584 | |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2585 | // Test that, if the server requests auth indefinitely, HttpNetworkTransaction |
| 2586 | // will eventually give up. |
| 2587 | TEST_F(HttpNetworkTransactionTest, BasicAuthForever) { |
| 2588 | HttpRequestInfo request; |
| 2589 | request.method = "GET"; |
| 2590 | request.url = GURL("http://www.example.org/"); |
| 2591 | request.traffic_annotation = |
| 2592 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 2593 | |
| 2594 | TestNetLog log; |
| 2595 | session_deps_.net_log = &log; |
| 2596 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 2597 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 2598 | |
| 2599 | MockWrite data_writes[] = { |
| 2600 | MockWrite("GET / HTTP/1.1\r\n" |
| 2601 | "Host: www.example.org\r\n" |
| 2602 | "Connection: keep-alive\r\n\r\n"), |
| 2603 | }; |
| 2604 | |
| 2605 | MockRead data_reads[] = { |
| 2606 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2607 | // Give a couple authenticate options (only the middle one is actually |
| 2608 | // supported). |
| 2609 | MockRead("WWW-Authenticate: Basic invalid\r\n"), // Malformed. |
| 2610 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2611 | MockRead("WWW-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 2612 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2613 | // Large content-length -- won't matter, as connection will be reset. |
| 2614 | MockRead("Content-Length: 10000\r\n\r\n"), |
| 2615 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 2616 | }; |
| 2617 | |
| 2618 | // After calling trans->RestartWithAuth(), this is the request we should |
| 2619 | // be issuing -- the final header line contains the credentials. |
| 2620 | MockWrite data_writes_restart[] = { |
| 2621 | MockWrite("GET / HTTP/1.1\r\n" |
| 2622 | "Host: www.example.org\r\n" |
| 2623 | "Connection: keep-alive\r\n" |
| 2624 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2625 | }; |
| 2626 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2627 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2628 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 2629 | |
| 2630 | TestCompletionCallback callback; |
| 2631 | int rv = callback.GetResult( |
| 2632 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 2633 | |
| 2634 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_restarts; |
| 2635 | for (int i = 0; i < 32; i++) { |
| 2636 | // Check the previous response was a 401. |
| 2637 | EXPECT_THAT(rv, IsOk()); |
| 2638 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 2639 | ASSERT_TRUE(response); |
| 2640 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 2641 | |
| 2642 | data_restarts.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2643 | data_reads, data_writes_restart)); |
David Benjamin | 83ddfb3 | 2018-03-30 01:07:52 | [diff] [blame] | 2644 | session_deps_.socket_factory->AddSocketDataProvider( |
| 2645 | data_restarts.back().get()); |
| 2646 | rv = callback.GetResult(trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2647 | callback.callback())); |
| 2648 | } |
| 2649 | |
| 2650 | // After too many tries, the transaction should have given up. |
| 2651 | EXPECT_THAT(rv, IsError(ERR_TOO_MANY_RETRIES)); |
| 2652 | } |
| 2653 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2654 | TEST_F(HttpNetworkTransactionTest, DoNotSendAuth) { |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2655 | HttpRequestInfo request; |
| 2656 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2657 | request.url = GURL("http://www.example.org/"); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 2658 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2659 | request.traffic_annotation = |
| 2660 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2661 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2662 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2663 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2664 | |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2665 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2666 | MockWrite( |
| 2667 | "GET / HTTP/1.1\r\n" |
| 2668 | "Host: www.example.org\r\n" |
| 2669 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2670 | }; |
| 2671 | |
| 2672 | MockRead data_reads[] = { |
| 2673 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 2674 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2675 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2676 | // Large content-length -- won't matter, as connection will be reset. |
| 2677 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2678 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2679 | }; |
| 2680 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2681 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2682 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2683 | TestCompletionCallback callback; |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2684 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2685 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2686 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2687 | |
| 2688 | rv = callback.WaitForResult(); |
| 2689 | EXPECT_EQ(0, rv); |
| 2690 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2691 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2692 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2693 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2694 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
[email protected] | b8015c4 | 2013-12-24 15:18:19 | [diff] [blame] | 2695 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2696 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2697 | ASSERT_TRUE(response); |
| 2698 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 861fcd5 | 2009-08-26 02:33:46 | [diff] [blame] | 2699 | } |
| 2700 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2701 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2702 | // connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2703 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAlive) { |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2704 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 2705 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 2706 | // reused. See http://crbug.com/544255. |
| 2707 | for (int i = 0; i < 2; ++i) { |
| 2708 | HttpRequestInfo request; |
| 2709 | request.method = "GET"; |
| 2710 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2711 | request.traffic_annotation = |
| 2712 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2713 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2714 | TestNetLog log; |
| 2715 | session_deps_.net_log = &log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2716 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2717 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2718 | MockWrite data_writes[] = { |
| 2719 | MockWrite(ASYNC, 0, |
| 2720 | "GET / HTTP/1.1\r\n" |
| 2721 | "Host: www.example.org\r\n" |
| 2722 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2723 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2724 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2725 | // be issuing -- the final header line contains the credentials. |
| 2726 | MockWrite(ASYNC, 6, |
| 2727 | "GET / HTTP/1.1\r\n" |
| 2728 | "Host: www.example.org\r\n" |
| 2729 | "Connection: keep-alive\r\n" |
| 2730 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 2731 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2732 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2733 | MockRead data_reads[] = { |
| 2734 | MockRead(ASYNC, 1, "HTTP/1.1 401 Unauthorized\r\n"), |
| 2735 | MockRead(ASYNC, 2, "WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2736 | MockRead(ASYNC, 3, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2737 | MockRead(ASYNC, 4, "Content-Length: 14\r\n\r\n"), |
| 2738 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 5, "Unauthorized\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2739 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2740 | // Lastly, the server responds with the actual content. |
| 2741 | MockRead(ASYNC, 7, "HTTP/1.1 200 OK\r\n"), |
| 2742 | MockRead(ASYNC, 8, "Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2743 | MockRead(ASYNC, 9, "Content-Length: 5\r\n\r\n"), |
| 2744 | MockRead(ASYNC, 10, "Hello"), |
| 2745 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2746 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2747 | SequencedSocketData data(data_reads, data_writes); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2748 | data.set_busy_before_sync_reads(true); |
| 2749 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2750 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2751 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2752 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2753 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2754 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2755 | ASSERT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2756 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2757 | LoadTimingInfo load_timing_info1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2758 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info1)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2759 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_DNS_TIMES); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2760 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2761 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2762 | ASSERT_TRUE(response); |
| 2763 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2764 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2765 | TestCompletionCallback callback2; |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 2766 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2767 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 2768 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2769 | ASSERT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2770 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2771 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2772 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info2)); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2773 | TestLoadTimingReused(load_timing_info2); |
| 2774 | // The load timing after restart should have the same socket ID, and times |
| 2775 | // those of the first load timing. |
| 2776 | EXPECT_LE(load_timing_info1.receive_headers_end, |
| 2777 | load_timing_info2.send_start); |
| 2778 | 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] | 2779 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2780 | response = trans.GetResponseInfo(); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2781 | ASSERT_TRUE(response); |
| 2782 | EXPECT_FALSE(response->auth_challenge); |
| 2783 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2784 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2785 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2786 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2787 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2788 | int64_t writes_size = CountWriteBytes(data_writes); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2789 | EXPECT_EQ(writes_size, trans.GetTotalSentBytes()); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2790 | int64_t reads_size = CountReadBytes(data_reads); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2791 | EXPECT_EQ(reads_size, trans.GetTotalReceivedBytes()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 2792 | } |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2793 | } |
| 2794 | |
| 2795 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2796 | // connection and with no response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2797 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2798 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2799 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2800 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2801 | request.traffic_annotation = |
| 2802 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2803 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2804 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2805 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2806 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2807 | MockWrite("GET / HTTP/1.1\r\n" |
| 2808 | "Host: www.example.org\r\n" |
| 2809 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2810 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2811 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2812 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2813 | MockWrite("GET / HTTP/1.1\r\n" |
| 2814 | "Host: www.example.org\r\n" |
| 2815 | "Connection: keep-alive\r\n" |
| 2816 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2817 | }; |
| 2818 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2819 | MockRead data_reads1[] = { |
| 2820 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2821 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2822 | MockRead("Content-Length: 0\r\n\r\n"), // No response body. |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2823 | |
| 2824 | // Lastly, the server responds with the actual content. |
| 2825 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2826 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2827 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2828 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2829 | }; |
| 2830 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2831 | // An incorrect reconnect would cause this to be read. |
| 2832 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2833 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2834 | }; |
| 2835 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2836 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2837 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2838 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2839 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2840 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2841 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2842 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2843 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2844 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2845 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2846 | |
| 2847 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2848 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2849 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2850 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2851 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2852 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2853 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2854 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2855 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2856 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2857 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2858 | |
| 2859 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2860 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2861 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2862 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2863 | ASSERT_TRUE(response); |
| 2864 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2865 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2866 | } |
| 2867 | |
| 2868 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 2869 | // connection and with a large response body to drain. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2870 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveLargeBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 2871 | HttpRequestInfo request; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2872 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2873 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2874 | request.traffic_annotation = |
| 2875 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2876 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2877 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2878 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2879 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2880 | MockWrite("GET / HTTP/1.1\r\n" |
| 2881 | "Host: www.example.org\r\n" |
| 2882 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2883 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2884 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2885 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2886 | MockWrite("GET / HTTP/1.1\r\n" |
| 2887 | "Host: www.example.org\r\n" |
| 2888 | "Connection: keep-alive\r\n" |
| 2889 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2890 | }; |
| 2891 | |
| 2892 | // Respond with 5 kb of response body. |
| 2893 | std::string large_body_string("Unauthorized"); |
| 2894 | large_body_string.append(5 * 1024, ' '); |
| 2895 | large_body_string.append("\r\n"); |
| 2896 | |
| 2897 | MockRead data_reads1[] = { |
| 2898 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2899 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2900 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2901 | // 5134 = 12 + 5 * 1024 + 2 |
| 2902 | MockRead("Content-Length: 5134\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2903 | MockRead(ASYNC, large_body_string.data(), large_body_string.size()), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2904 | |
| 2905 | // Lastly, the server responds with the actual content. |
| 2906 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2907 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2908 | MockRead("Content-Length: 5\r\n\r\n"), |
| 2909 | MockRead("hello"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2910 | }; |
| 2911 | |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2912 | // An incorrect reconnect would cause this to be read. |
| 2913 | MockRead data_reads2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2914 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 2d0a4f9 | 2011-05-05 16:38:46 | [diff] [blame] | 2915 | }; |
| 2916 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 2917 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 2918 | StaticSocketDataProvider data2(data_reads2, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 2919 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 2920 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2921 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2922 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2923 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2924 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 2925 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2926 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2927 | |
| 2928 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2929 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [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); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 2933 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2934 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 2935 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2936 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2937 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2938 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2939 | |
| 2940 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 2941 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2942 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2943 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 2944 | ASSERT_TRUE(response); |
| 2945 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2946 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 2947 | } |
| 2948 | |
| 2949 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2950 | // connection, but the server gets impatient and closes the connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 2951 | TEST_F(HttpNetworkTransactionTest, BasicAuthKeepAliveImpatientServer) { |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2952 | HttpRequestInfo request; |
| 2953 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2954 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 2955 | request.traffic_annotation = |
| 2956 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2957 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 2958 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 2959 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2960 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2961 | MockWrite( |
| 2962 | "GET / HTTP/1.1\r\n" |
| 2963 | "Host: www.example.org\r\n" |
| 2964 | "Connection: keep-alive\r\n\r\n"), |
| 2965 | // This simulates the seemingly successful write to a closed connection |
| 2966 | // if the bug is not fixed. |
| 2967 | MockWrite( |
| 2968 | "GET / HTTP/1.1\r\n" |
| 2969 | "Host: www.example.org\r\n" |
| 2970 | "Connection: keep-alive\r\n" |
| 2971 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2972 | }; |
| 2973 | |
| 2974 | MockRead data_reads1[] = { |
| 2975 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 2976 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 2977 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 2978 | MockRead("Content-Length: 14\r\n\r\n"), |
| 2979 | // Tell MockTCPClientSocket to simulate the server closing the connection. |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2980 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2981 | MockRead("Unauthorized\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 2982 | MockRead(SYNCHRONOUS, OK), // The server closes the connection. |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2983 | }; |
| 2984 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 2985 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2986 | // be issuing -- the final header line contains the credentials. |
| 2987 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 2988 | MockWrite( |
| 2989 | "GET / HTTP/1.1\r\n" |
| 2990 | "Host: www.example.org\r\n" |
| 2991 | "Connection: keep-alive\r\n" |
| 2992 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 2993 | }; |
| 2994 | |
| 2995 | // Lastly, the server responds with the actual content. |
| 2996 | MockRead data_reads2[] = { |
| 2997 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 2998 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 2999 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3000 | MockRead("hello"), |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3001 | }; |
| 3002 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3003 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 3004 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3005 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3006 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3007 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3008 | TestCompletionCallback callback1; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3009 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3010 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3011 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3012 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3013 | |
| 3014 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3015 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3016 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3017 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3018 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3019 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3020 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3021 | TestCompletionCallback callback2; |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3022 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3023 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3024 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3025 | |
| 3026 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3027 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3028 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3029 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3030 | ASSERT_TRUE(response); |
| 3031 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3032 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3033 | } |
| 3034 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3035 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3036 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3037 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp10) { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3038 | HttpRequestInfo request; |
| 3039 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3040 | request.url = GURL("https://www.example.org/"); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3041 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3042 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3043 | request.traffic_annotation = |
| 3044 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3045 | |
| 3046 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3047 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3048 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3049 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3050 | BoundTestNetLog log; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3051 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3052 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3053 | |
| 3054 | // Since we have proxy, should try to establish tunnel. |
| 3055 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3056 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3057 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3058 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3059 | }; |
| 3060 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3061 | // The proxy responds to the connect with a 407, using a non-persistent |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3062 | // connection. |
| 3063 | MockRead data_reads1[] = { |
| 3064 | // No credentials. |
| 3065 | MockRead("HTTP/1.0 407 Proxy Authentication Required\r\n"), |
| 3066 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n\r\n"), |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3067 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3068 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3069 | // Since the first connection couldn't be reused, need to establish another |
| 3070 | // once given credentials. |
| 3071 | MockWrite data_writes2[] = { |
| 3072 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3073 | // be issuing -- the final header line contains the credentials. |
| 3074 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3075 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3076 | "Proxy-Connection: keep-alive\r\n" |
| 3077 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3078 | |
| 3079 | MockWrite("GET / HTTP/1.1\r\n" |
| 3080 | "Host: www.example.org\r\n" |
| 3081 | "Connection: keep-alive\r\n\r\n"), |
| 3082 | }; |
| 3083 | |
| 3084 | MockRead data_reads2[] = { |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3085 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 3086 | |
| 3087 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3088 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3089 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3090 | MockRead(SYNCHRONOUS, "hello"), |
| 3091 | }; |
| 3092 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3093 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3094 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3095 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3096 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3097 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3098 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3099 | |
| 3100 | TestCompletionCallback callback1; |
| 3101 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3102 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3103 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3104 | |
| 3105 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3106 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3107 | |
| 3108 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3109 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3110 | TestNetLogEntry::List entries; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3111 | log.GetEntries(&entries); |
| 3112 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3113 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3114 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3115 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3116 | entries, pos, |
| 3117 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3118 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3119 | |
| 3120 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3121 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3122 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3123 | ASSERT_TRUE(response->headers); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3124 | EXPECT_EQ(407, response->headers->response_code()); |
| 3125 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3126 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3127 | |
| 3128 | LoadTimingInfo load_timing_info; |
| 3129 | // CONNECT requests and responses are handled at the connect job level, so |
| 3130 | // the transaction does not yet have a connection. |
| 3131 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3132 | |
| 3133 | TestCompletionCallback callback2; |
| 3134 | |
| 3135 | rv = |
| 3136 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3137 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3138 | |
| 3139 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3140 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3141 | |
| 3142 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3143 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3144 | |
| 3145 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3146 | EXPECT_EQ(200, response->headers->response_code()); |
| 3147 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 3148 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3149 | |
| 3150 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3151 | EXPECT_FALSE(response->auth_challenge); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3152 | |
| 3153 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3154 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3155 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3156 | |
| 3157 | trans.reset(); |
| 3158 | session->CloseAllConnections(); |
| 3159 | } |
| 3160 | |
| 3161 | // Test the request-challenge-retry sequence for basic auth, over a connection |
| 3162 | // that requires a restart when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3163 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyNoKeepAliveHttp11) { |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3164 | HttpRequestInfo request; |
| 3165 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3166 | request.url = GURL("https://www.example.org/"); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3167 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3168 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3169 | request.traffic_annotation = |
| 3170 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3171 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3172 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3173 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3174 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3175 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3176 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3177 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3178 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3179 | |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3180 | // Since we have proxy, should try to establish tunnel. |
| 3181 | MockWrite data_writes1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3182 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3183 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3184 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3185 | }; |
| 3186 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3187 | // The proxy responds to the connect with a 407, using a non-persistent |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3188 | // connection. |
| 3189 | MockRead data_reads1[] = { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3190 | // No credentials. |
| 3191 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3192 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3193 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3194 | }; |
mmenke | e0b5c88 | 2015-08-26 20:29:11 | [diff] [blame] | 3195 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3196 | MockWrite data_writes2[] = { |
| 3197 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3198 | // be issuing -- the final header line contains the credentials. |
| 3199 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3200 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3201 | "Proxy-Connection: keep-alive\r\n" |
| 3202 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
mmenke | 0fd148d | 2015-09-30 23:00:08 | [diff] [blame] | 3203 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3204 | MockWrite("GET / HTTP/1.1\r\n" |
| 3205 | "Host: www.example.org\r\n" |
| 3206 | "Connection: keep-alive\r\n\r\n"), |
| 3207 | }; |
| 3208 | |
| 3209 | MockRead data_reads2[] = { |
| 3210 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3211 | |
| 3212 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3213 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3214 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3215 | MockRead(SYNCHRONOUS, "hello"), |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3216 | }; |
| 3217 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3218 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3219 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3220 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3221 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3222 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3223 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3224 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3225 | TestCompletionCallback callback1; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3226 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3227 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3228 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3229 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3230 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3231 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3232 | |
| 3233 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3234 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3235 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3236 | log.GetEntries(&entries); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3237 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3238 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3239 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3240 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3241 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3242 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3243 | NetLogEventPhase::NONE); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3244 | |
| 3245 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3246 | ASSERT_TRUE(response); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3247 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3248 | ASSERT_TRUE(response->headers); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3249 | EXPECT_EQ(407, response->headers->response_code()); |
| 3250 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3251 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3252 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3253 | LoadTimingInfo load_timing_info; |
| 3254 | // CONNECT requests and responses are handled at the connect job level, so |
| 3255 | // the transaction does not yet have a connection. |
| 3256 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3257 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3258 | TestCompletionCallback callback2; |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3259 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3260 | rv = trans->RestartWithAuth( |
| 3261 | AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3262 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3263 | |
| 3264 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3265 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3266 | |
| 3267 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3268 | ASSERT_TRUE(response); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3269 | |
| 3270 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3271 | EXPECT_EQ(200, response->headers->response_code()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3272 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3273 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3274 | |
| 3275 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 3276 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3277 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 3278 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3279 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3280 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3281 | |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 3282 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3283 | session->CloseAllConnections(); |
[email protected] | 394816e9 | 2010-08-03 07:38:59 | [diff] [blame] | 3284 | } |
| 3285 | |
[email protected] | 11203f01 | 2009-11-12 23:02:31 | [diff] [blame] | 3286 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3287 | // proxy connection with HTTP/1.0 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3288 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp10) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3289 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3290 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3291 | // reused. See http://crbug.com/544255. |
| 3292 | for (int i = 0; i < 2; ++i) { |
| 3293 | HttpRequestInfo request; |
| 3294 | request.method = "GET"; |
| 3295 | request.url = GURL("https://www.example.org/"); |
| 3296 | // Ensure that proxy authentication is attempted even |
| 3297 | // when the no authentication data flag is set. |
| 3298 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3299 | request.traffic_annotation = |
| 3300 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3301 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3302 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3303 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3304 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3305 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3306 | BoundTestNetLog log; |
| 3307 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3308 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3309 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3310 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3311 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3312 | // Since we have proxy, should try to establish tunnel. |
| 3313 | MockWrite data_writes1[] = { |
| 3314 | MockWrite(ASYNC, 0, |
| 3315 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3316 | "Host: www.example.org:443\r\n" |
| 3317 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3318 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3319 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3320 | // be issuing -- the final header line contains the credentials. |
| 3321 | MockWrite(ASYNC, 3, |
| 3322 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3323 | "Host: www.example.org:443\r\n" |
| 3324 | "Proxy-Connection: keep-alive\r\n" |
| 3325 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3326 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3327 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3328 | // The proxy responds to the connect with a 407, using a persistent |
| 3329 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3330 | MockRead data_reads1[] = { |
| 3331 | // No credentials. |
| 3332 | MockRead(ASYNC, 1, |
| 3333 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3334 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3335 | "Proxy-Connection: keep-alive\r\n" |
| 3336 | "Content-Length: 10\r\n\r\n"), |
| 3337 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3338 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3339 | // Wrong credentials (wrong password). |
| 3340 | MockRead(ASYNC, 4, |
| 3341 | "HTTP/1.0 407 Proxy Authentication Required\r\n" |
| 3342 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3343 | "Proxy-Connection: keep-alive\r\n" |
| 3344 | "Content-Length: 10\r\n\r\n"), |
| 3345 | // No response body because the test stops reading here. |
| 3346 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3347 | }; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3348 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3349 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3350 | data1.set_busy_before_sync_reads(true); |
| 3351 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3352 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3353 | TestCompletionCallback callback1; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3354 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3355 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3356 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3357 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3358 | TestNetLogEntry::List entries; |
| 3359 | log.GetEntries(&entries); |
| 3360 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3361 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3362 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3363 | ExpectLogContainsSomewhere( |
| 3364 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3365 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3366 | NetLogEventPhase::NONE); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3367 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3368 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3369 | ASSERT_TRUE(response); |
| 3370 | ASSERT_TRUE(response->headers); |
| 3371 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3372 | EXPECT_EQ(407, response->headers->response_code()); |
| 3373 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3374 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3375 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3376 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3377 | TestCompletionCallback callback2; |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3378 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3379 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3380 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3381 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3382 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3383 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3384 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3385 | ASSERT_TRUE(response); |
| 3386 | ASSERT_TRUE(response->headers); |
| 3387 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3388 | EXPECT_EQ(407, response->headers->response_code()); |
| 3389 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3390 | EXPECT_TRUE(HttpVersion(1, 0) == response->headers->GetHttpVersion()); |
| 3391 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3392 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3393 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3394 | // out of scope. |
| 3395 | session->CloseAllConnections(); |
| 3396 | } |
ttuttle | 34f63b5 | 2015-03-05 04:33:01 | [diff] [blame] | 3397 | } |
| 3398 | |
| 3399 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3400 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3401 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHttp11) { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3402 | // On the second pass, the body read of the auth challenge is synchronous, so |
| 3403 | // IsConnectedAndIdle returns false. The socket should still be drained and |
| 3404 | // reused. See http://crbug.com/544255. |
| 3405 | for (int i = 0; i < 2; ++i) { |
| 3406 | HttpRequestInfo request; |
| 3407 | request.method = "GET"; |
| 3408 | request.url = GURL("https://www.example.org/"); |
| 3409 | // Ensure that proxy authentication is attempted even |
| 3410 | // when the no authentication data flag is set. |
| 3411 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3412 | request.traffic_annotation = |
| 3413 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3414 | |
| 3415 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3416 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3417 | ProxyResolutionService::CreateFixed("myproxy:70", |
| 3418 | TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3419 | BoundTestNetLog log; |
| 3420 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3421 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3422 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3423 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3424 | |
| 3425 | // Since we have proxy, should try to establish tunnel. |
| 3426 | MockWrite data_writes1[] = { |
| 3427 | MockWrite(ASYNC, 0, |
| 3428 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3429 | "Host: www.example.org:443\r\n" |
| 3430 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3431 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3432 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3433 | // be issuing -- the final header line contains the credentials. |
| 3434 | MockWrite(ASYNC, 3, |
| 3435 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3436 | "Host: www.example.org:443\r\n" |
| 3437 | "Proxy-Connection: keep-alive\r\n" |
| 3438 | "Proxy-Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
| 3439 | }; |
| 3440 | |
| 3441 | // The proxy responds to the connect with a 407, using a persistent |
| 3442 | // connection. (Since it's HTTP/1.0, keep-alive has to be explicit.) |
| 3443 | MockRead data_reads1[] = { |
| 3444 | // No credentials. |
| 3445 | MockRead(ASYNC, 1, |
| 3446 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3447 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3448 | "Content-Length: 10\r\n\r\n"), |
| 3449 | MockRead(i == 0 ? ASYNC : SYNCHRONOUS, 2, "0123456789"), |
| 3450 | |
| 3451 | // Wrong credentials (wrong password). |
| 3452 | MockRead(ASYNC, 4, |
| 3453 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3454 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3455 | "Content-Length: 10\r\n\r\n"), |
| 3456 | // No response body because the test stops reading here. |
| 3457 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 5), |
| 3458 | }; |
| 3459 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3460 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3461 | data1.set_busy_before_sync_reads(true); |
| 3462 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 3463 | |
| 3464 | TestCompletionCallback callback1; |
| 3465 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3466 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3467 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3468 | |
| 3469 | TestNetLogEntry::List entries; |
| 3470 | log.GetEntries(&entries); |
| 3471 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3472 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3473 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3474 | ExpectLogContainsSomewhere( |
| 3475 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3476 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3477 | NetLogEventPhase::NONE); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3478 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3479 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3480 | ASSERT_TRUE(response); |
| 3481 | ASSERT_TRUE(response->headers); |
| 3482 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3483 | EXPECT_EQ(407, response->headers->response_code()); |
| 3484 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3485 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3486 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3487 | |
| 3488 | TestCompletionCallback callback2; |
| 3489 | |
| 3490 | // Wrong password (should be "bar"). |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3491 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBaz), |
| 3492 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3493 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3494 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3495 | response = trans.GetResponseInfo(); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3496 | ASSERT_TRUE(response); |
| 3497 | ASSERT_TRUE(response->headers); |
| 3498 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3499 | EXPECT_EQ(407, response->headers->response_code()); |
| 3500 | EXPECT_EQ(10, response->headers->GetContentLength()); |
| 3501 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3502 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3503 | |
| 3504 | // Flush the idle socket before the NetLog and HttpNetworkTransaction go |
| 3505 | // out of scope. |
| 3506 | session->CloseAllConnections(); |
| 3507 | } |
| 3508 | } |
| 3509 | |
| 3510 | // Test the request-challenge-retry sequence for basic auth, over a keep-alive |
| 3511 | // proxy connection with HTTP/1.1 responses, when setting up an SSL tunnel, in |
| 3512 | // the case the server sends extra data on the original socket, so it can't be |
| 3513 | // reused. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3514 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveExtraData) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3515 | HttpRequestInfo request; |
| 3516 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3517 | request.url = GURL("https://www.example.org/"); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3518 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 3519 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3520 | request.traffic_annotation = |
| 3521 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3522 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3523 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3524 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3525 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3526 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3527 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3528 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3529 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3530 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3531 | // Since we have proxy, should try to establish tunnel. |
| 3532 | MockWrite data_writes1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3533 | MockWrite(ASYNC, 0, |
| 3534 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3535 | "Host: www.example.org:443\r\n" |
| 3536 | "Proxy-Connection: keep-alive\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3537 | }; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3538 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3539 | // The proxy responds to the connect with a 407, using a persistent, but sends |
| 3540 | // extra data, so the socket cannot be reused. |
| 3541 | MockRead data_reads1[] = { |
| 3542 | // No credentials. |
| 3543 | MockRead(ASYNC, 1, |
| 3544 | "HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 3545 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 3546 | "Content-Length: 10\r\n\r\n"), |
| 3547 | MockRead(SYNCHRONOUS, 2, "0123456789"), |
| 3548 | MockRead(SYNCHRONOUS, 3, "I'm broken!"), |
| 3549 | }; |
| 3550 | |
| 3551 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3552 | // After calling trans->RestartWithAuth(), this is the request we should |
| 3553 | // be issuing -- the final header line contains the credentials. |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3554 | MockWrite(ASYNC, 0, |
| 3555 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3556 | "Host: www.example.org:443\r\n" |
| 3557 | "Proxy-Connection: keep-alive\r\n" |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3558 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3559 | |
| 3560 | MockWrite(ASYNC, 2, |
| 3561 | "GET / HTTP/1.1\r\n" |
| 3562 | "Host: www.example.org\r\n" |
| 3563 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3564 | }; |
| 3565 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3566 | MockRead data_reads2[] = { |
| 3567 | MockRead(ASYNC, 1, "HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3568 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3569 | MockRead(ASYNC, 3, |
| 3570 | "HTTP/1.1 200 OK\r\n" |
| 3571 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 3572 | "Content-Length: 5\r\n\r\n"), |
| 3573 | // No response body because the test stops reading here. |
| 3574 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED, 4), |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3575 | }; |
| 3576 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3577 | SequencedSocketData data1(data_reads1, data_writes1); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3578 | data1.set_busy_before_sync_reads(true); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3579 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3580 | SequencedSocketData data2(data_reads2, data_writes2); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3581 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3582 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3583 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3584 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3585 | TestCompletionCallback callback1; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3586 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 3587 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3588 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3589 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [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()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3592 | |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3593 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3594 | log.GetEntries(&entries); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 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); |
[email protected] | dbb83db | 2010-05-11 18:13:39 | [diff] [blame] | 3598 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3599 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3600 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3601 | NetLogEventPhase::NONE); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3602 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3603 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3604 | ASSERT_TRUE(response); |
| 3605 | ASSERT_TRUE(response->headers); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3606 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3607 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3608 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 3609 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3610 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3611 | LoadTimingInfo load_timing_info; |
| 3612 | // CONNECT requests and responses are handled at the connect job level, so |
| 3613 | // the transaction does not yet have a connection. |
| 3614 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3615 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3616 | TestCompletionCallback callback2; |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3617 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3618 | rv = |
| 3619 | trans->RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3620 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3621 | |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3622 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3623 | EXPECT_EQ(200, response->headers->response_code()); |
| 3624 | EXPECT_EQ(5, response->headers->GetContentLength()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3625 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | e772db3f | 2010-07-12 18:11:13 | [diff] [blame] | 3626 | |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3627 | // The password prompt info should not be set. |
| 3628 | EXPECT_FALSE(response->auth_challenge); |
| 3629 | |
| 3630 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 3631 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 3632 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 3633 | |
| 3634 | trans.reset(); |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3635 | session->CloseAllConnections(); |
[email protected] | 2d2697f9 | 2009-02-18 21:00:32 | [diff] [blame] | 3636 | } |
| 3637 | |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3638 | // Test the case a proxy closes a socket while the challenge body is being |
| 3639 | // drained. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3640 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyKeepAliveHangupDuringBody) { |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 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 | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3649 | |
| 3650 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3651 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3652 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3653 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3654 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3655 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3656 | |
| 3657 | // Since we have proxy, should try to establish tunnel. |
| 3658 | MockWrite data_writes1[] = { |
| 3659 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3660 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3661 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3662 | }; |
| 3663 | |
| 3664 | // The proxy responds to the connect with a 407, using a persistent |
| 3665 | // connection. |
| 3666 | MockRead data_reads1[] = { |
| 3667 | // No credentials. |
| 3668 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3669 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3670 | MockRead("Content-Length: 10\r\n\r\n"), MockRead("spam!"), |
| 3671 | // Server hands up in the middle of the body. |
| 3672 | MockRead(ASYNC, ERR_CONNECTION_CLOSED), |
| 3673 | }; |
| 3674 | |
| 3675 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3676 | // After calling trans.RestartWithAuth(), this is the request we should |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3677 | // be issuing -- the final header line contains the credentials. |
| 3678 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3679 | "Host: www.example.org:443\r\n" |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3680 | "Proxy-Connection: keep-alive\r\n" |
| 3681 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
| 3682 | |
| 3683 | MockWrite("GET / HTTP/1.1\r\n" |
| 3684 | "Host: www.example.org\r\n" |
| 3685 | "Connection: keep-alive\r\n\r\n"), |
| 3686 | }; |
| 3687 | |
| 3688 | MockRead data_reads2[] = { |
| 3689 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3690 | |
| 3691 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 3692 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 3693 | MockRead("Content-Length: 5\r\n\r\n"), |
| 3694 | MockRead(SYNCHRONOUS, "hello"), |
| 3695 | }; |
| 3696 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3697 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3698 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3699 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3700 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 3701 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 3702 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 3703 | |
| 3704 | TestCompletionCallback callback; |
| 3705 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3706 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3707 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3708 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3709 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3710 | ASSERT_TRUE(response); |
| 3711 | ASSERT_TRUE(response->headers); |
| 3712 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3713 | EXPECT_EQ(407, response->headers->response_code()); |
| 3714 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
| 3715 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3716 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3717 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3718 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3719 | response = trans.GetResponseInfo(); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3720 | ASSERT_TRUE(response); |
| 3721 | ASSERT_TRUE(response->headers); |
| 3722 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3723 | EXPECT_EQ(200, response->headers->response_code()); |
| 3724 | std::string body; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3725 | EXPECT_THAT(ReadTransaction(&trans, &body), IsOk()); |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 3726 | EXPECT_EQ("hello", body); |
| 3727 | } |
| 3728 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3729 | // Test that we don't read the response body when we fail to establish a tunnel, |
| 3730 | // even if the user cancels the proxy's auth attempt. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3731 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyCancelTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3732 | HttpRequestInfo request; |
| 3733 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3734 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3735 | request.traffic_annotation = |
| 3736 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3737 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3738 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3739 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3740 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3741 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3742 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3743 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3744 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3745 | |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3746 | // Since we have proxy, should try to establish tunnel. |
| 3747 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3748 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3749 | "Host: www.example.org:443\r\n" |
| 3750 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3751 | }; |
| 3752 | |
| 3753 | // The proxy responds to the connect with a 407. |
| 3754 | MockRead data_reads[] = { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3755 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3756 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3757 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3758 | MockRead("0123456789"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3759 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3760 | }; |
| 3761 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3762 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3763 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3764 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3765 | TestCompletionCallback callback; |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3766 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3767 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3768 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3769 | |
| 3770 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3771 | EXPECT_THAT(rv, IsOk()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3772 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3773 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3774 | ASSERT_TRUE(response); |
| 3775 | ASSERT_TRUE(response->headers); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3776 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3777 | EXPECT_EQ(407, response->headers->response_code()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 3778 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3779 | |
| 3780 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3781 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3782 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 3783 | |
| 3784 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
[email protected] | 102e27c | 2011-02-23 01:01:31 | [diff] [blame] | 3785 | session->CloseAllConnections(); |
[email protected] | a8e9b16 | 2009-03-12 00:06:44 | [diff] [blame] | 3786 | } |
| 3787 | |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3788 | // Test that we don't pass extraneous headers from the proxy's response to the |
| 3789 | // caller when the proxy responds to CONNECT with 407. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3790 | TEST_F(HttpNetworkTransactionTest, SanitizeProxyAuthHeaders) { |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3791 | HttpRequestInfo request; |
| 3792 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3793 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3794 | request.traffic_annotation = |
| 3795 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3796 | |
| 3797 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3798 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3799 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3800 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3801 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3802 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3803 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3804 | |
| 3805 | // Since we have proxy, should try to establish tunnel. |
| 3806 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3807 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3808 | "Host: www.example.org:443\r\n" |
| 3809 | "Proxy-Connection: keep-alive\r\n\r\n"), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3810 | }; |
| 3811 | |
| 3812 | // The proxy responds to the connect with a 407. |
| 3813 | MockRead data_reads[] = { |
| 3814 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3815 | MockRead("X-Foo: bar\r\n"), |
| 3816 | MockRead("Set-Cookie: foo=bar\r\n"), |
| 3817 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3818 | MockRead("Content-Length: 10\r\n\r\n"), |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 3819 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3820 | }; |
| 3821 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3822 | StaticSocketDataProvider data(data_reads, data_writes); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3823 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 3824 | |
| 3825 | TestCompletionCallback callback; |
| 3826 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3827 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3828 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3829 | |
| 3830 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3831 | EXPECT_THAT(rv, IsOk()); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3832 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3833 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3834 | ASSERT_TRUE(response); |
| 3835 | ASSERT_TRUE(response->headers); |
| 3836 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 3837 | EXPECT_EQ(407, response->headers->response_code()); |
| 3838 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 3839 | EXPECT_FALSE(response->headers->HasHeader("X-Foo")); |
| 3840 | EXPECT_FALSE(response->headers->HasHeader("Set-Cookie")); |
| 3841 | |
| 3842 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3843 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3844 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
ttuttle | 7933c11 | 2015-01-06 00:55:24 | [diff] [blame] | 3845 | |
| 3846 | // Flush the idle socket before the HttpNetworkTransaction goes out of scope. |
| 3847 | session->CloseAllConnections(); |
| 3848 | } |
| 3849 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3850 | // Test when a server (non-proxy) returns a 407 (proxy-authenticate). |
| 3851 | // The request should fail with ERR_UNEXPECTED_PROXY_AUTH. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3852 | TEST_F(HttpNetworkTransactionTest, UnexpectedProxyAuth) { |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3853 | HttpRequestInfo request; |
| 3854 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3855 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3856 | request.traffic_annotation = |
| 3857 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3858 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3859 | // We are using a DIRECT connection (i.e. no proxy) for this session. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3860 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3861 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3862 | |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3863 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3864 | MockWrite( |
| 3865 | "GET / HTTP/1.1\r\n" |
| 3866 | "Host: www.example.org\r\n" |
| 3867 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3868 | }; |
| 3869 | |
| 3870 | MockRead data_reads1[] = { |
| 3871 | MockRead("HTTP/1.0 407 Proxy Auth required\r\n"), |
| 3872 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3873 | // Large content-length -- won't matter, as connection will be reset. |
| 3874 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3875 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3876 | }; |
| 3877 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3878 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3879 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3880 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3881 | TestCompletionCallback callback; |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3882 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 3883 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3884 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3885 | |
| 3886 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3887 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
[email protected] | 8fdbcd2 | 2010-05-05 02:54:52 | [diff] [blame] | 3888 | } |
| 3889 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3890 | // Tests when an HTTPS server (non-proxy) returns a 407 (proxy-authentication) |
| 3891 | // through a non-authenticating proxy. The request should fail with |
| 3892 | // ERR_UNEXPECTED_PROXY_AUTH. |
| 3893 | // Note that it is impossible to detect if an HTTP server returns a 407 through |
| 3894 | // a non-authenticating proxy - there is nothing to indicate whether the |
| 3895 | // response came from the proxy or the server, so it is treated as if the proxy |
| 3896 | // issued the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3897 | TEST_F(HttpNetworkTransactionTest, HttpsServerRequestsProxyAuthThroughProxy) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3898 | HttpRequestInfo request; |
| 3899 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 3900 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3901 | request.traffic_annotation = |
| 3902 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 3903 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3904 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 3905 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 3906 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3907 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3908 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3909 | |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3910 | // Since we have proxy, should try to establish tunnel. |
| 3911 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3912 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 3913 | "Host: www.example.org:443\r\n" |
| 3914 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3915 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3916 | MockWrite("GET / HTTP/1.1\r\n" |
| 3917 | "Host: www.example.org\r\n" |
| 3918 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3919 | }; |
| 3920 | |
| 3921 | MockRead data_reads1[] = { |
| 3922 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 3923 | |
| 3924 | MockRead("HTTP/1.1 407 Unauthorized\r\n"), |
| 3925 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 3926 | MockRead("\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3927 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3928 | }; |
| 3929 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 3930 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3931 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 3932 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 3933 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3934 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 3935 | TestCompletionCallback callback1; |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3936 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3937 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3938 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 3939 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3940 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3941 | |
| 3942 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 3943 | EXPECT_THAT(rv, IsError(ERR_UNEXPECTED_PROXY_AUTH)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 3944 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3945 | log.GetEntries(&entries); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3946 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3947 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 3948 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3949 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 3950 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 3951 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 3952 | NetLogEventPhase::NONE); |
[email protected] | 7a67a815 | 2010-11-05 18:31:10 | [diff] [blame] | 3953 | } |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 3954 | |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3955 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 3956 | // that uses non-persistent connections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 3957 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3958 | AuthAllowsDefaultCredentialsTunnelConnectionClose) { |
| 3959 | HttpRequestInfo request; |
| 3960 | request.method = "GET"; |
| 3961 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 3962 | request.traffic_annotation = |
| 3963 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3964 | |
| 3965 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 3966 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 3967 | ProxyResolutionService::CreateFixedFromPacResult( |
| 3968 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3969 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3970 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3971 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 3972 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3973 | mock_handler->set_allows_default_credentials(true); |
| 3974 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 3975 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 3976 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3977 | |
| 3978 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 3979 | NetLog net_log; |
| 3980 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 3981 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3982 | |
| 3983 | // Since we have proxy, should try to establish tunnel. |
| 3984 | MockWrite data_writes1[] = { |
| 3985 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 3986 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 3987 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 3988 | }; |
| 3989 | |
| 3990 | // The proxy responds to the connect with a 407, using a non-persistent |
| 3991 | // connection. |
| 3992 | MockRead data_reads1[] = { |
| 3993 | // No credentials. |
| 3994 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 3995 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 3996 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 3997 | }; |
| 3998 | |
| 3999 | // Since the first connection couldn't be reused, need to establish another |
| 4000 | // once given credentials. |
| 4001 | MockWrite data_writes2[] = { |
| 4002 | // After calling trans->RestartWithAuth(), this is the request we should |
| 4003 | // be issuing -- the final header line contains the credentials. |
| 4004 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4005 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4006 | "Proxy-Connection: keep-alive\r\n" |
| 4007 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4008 | |
| 4009 | MockWrite("GET / HTTP/1.1\r\n" |
| 4010 | "Host: www.example.org\r\n" |
| 4011 | "Connection: keep-alive\r\n\r\n"), |
| 4012 | }; |
| 4013 | |
| 4014 | MockRead data_reads2[] = { |
| 4015 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4016 | |
| 4017 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4018 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4019 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4020 | MockRead(SYNCHRONOUS, "hello"), |
| 4021 | }; |
| 4022 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4023 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4024 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4025 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4026 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4027 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4028 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4029 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4030 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4031 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4032 | |
| 4033 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4034 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4035 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4036 | |
| 4037 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4038 | ASSERT_TRUE(response); |
| 4039 | ASSERT_TRUE(response->headers); |
| 4040 | EXPECT_FALSE(response->headers->IsKeepAlive()); |
| 4041 | EXPECT_EQ(407, response->headers->response_code()); |
| 4042 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4043 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4044 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4045 | |
| 4046 | LoadTimingInfo load_timing_info; |
| 4047 | // CONNECT requests and responses are handled at the connect job level, so |
| 4048 | // the transaction does not yet have a connection. |
| 4049 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4050 | |
| 4051 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4052 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4053 | response = trans->GetResponseInfo(); |
| 4054 | ASSERT_TRUE(response); |
| 4055 | ASSERT_TRUE(response->headers); |
| 4056 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4057 | EXPECT_EQ(200, response->headers->response_code()); |
| 4058 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4059 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4060 | |
| 4061 | // The password prompt info should not be set. |
| 4062 | EXPECT_FALSE(response->auth_challenge); |
| 4063 | |
| 4064 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4065 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4066 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4067 | |
| 4068 | trans.reset(); |
| 4069 | session->CloseAllConnections(); |
| 4070 | } |
| 4071 | |
| 4072 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4073 | // that hangs up when credentials are initially sent. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4074 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4075 | AuthAllowsDefaultCredentialsTunnelServerClosesConnection) { |
| 4076 | HttpRequestInfo request; |
| 4077 | request.method = "GET"; |
| 4078 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4079 | request.traffic_annotation = |
| 4080 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4081 | |
| 4082 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4083 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4084 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4085 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4086 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4087 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4088 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4089 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4090 | mock_handler->set_allows_default_credentials(true); |
| 4091 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4092 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4093 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4094 | |
| 4095 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4096 | NetLog net_log; |
| 4097 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4098 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4099 | |
| 4100 | // Should try to establish tunnel. |
| 4101 | MockWrite data_writes1[] = { |
| 4102 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4103 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4104 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4105 | |
| 4106 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4107 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4108 | "Proxy-Connection: keep-alive\r\n" |
| 4109 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4110 | }; |
| 4111 | |
| 4112 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4113 | // connection. |
| 4114 | MockRead data_reads1[] = { |
| 4115 | // No credentials. |
| 4116 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4117 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4118 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4119 | }; |
| 4120 | |
| 4121 | // Since the first connection was closed, need to establish another once given |
| 4122 | // credentials. |
| 4123 | MockWrite data_writes2[] = { |
| 4124 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4125 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4126 | "Proxy-Connection: keep-alive\r\n" |
| 4127 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4128 | |
| 4129 | MockWrite("GET / HTTP/1.1\r\n" |
| 4130 | "Host: www.example.org\r\n" |
| 4131 | "Connection: keep-alive\r\n\r\n"), |
| 4132 | }; |
| 4133 | |
| 4134 | MockRead data_reads2[] = { |
| 4135 | MockRead("HTTP/1.0 200 Connection Established\r\n\r\n"), |
| 4136 | |
| 4137 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4138 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4139 | MockRead("Content-Length: 5\r\n\r\n"), |
| 4140 | MockRead(SYNCHRONOUS, "hello"), |
| 4141 | }; |
| 4142 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4143 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4144 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4145 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4146 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4147 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4148 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4149 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4150 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4151 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4152 | |
| 4153 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4154 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4155 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4156 | |
| 4157 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4158 | ASSERT_TRUE(response); |
| 4159 | ASSERT_TRUE(response->headers); |
| 4160 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4161 | EXPECT_EQ(407, response->headers->response_code()); |
| 4162 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4163 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4164 | EXPECT_FALSE(response->auth_challenge); |
| 4165 | |
| 4166 | LoadTimingInfo load_timing_info; |
| 4167 | // CONNECT requests and responses are handled at the connect job level, so |
| 4168 | // the transaction does not yet have a connection. |
| 4169 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4170 | |
| 4171 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4172 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4173 | |
| 4174 | response = trans->GetResponseInfo(); |
| 4175 | ASSERT_TRUE(response); |
| 4176 | ASSERT_TRUE(response->headers); |
| 4177 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 4178 | EXPECT_EQ(200, response->headers->response_code()); |
| 4179 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 4180 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4181 | |
| 4182 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4183 | EXPECT_FALSE(response->auth_challenge); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4184 | |
| 4185 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4186 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 4187 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4188 | |
| 4189 | trans.reset(); |
| 4190 | session->CloseAllConnections(); |
| 4191 | } |
| 4192 | |
| 4193 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4194 | // that hangs up when credentials are initially sent, and hangs up again when |
| 4195 | // they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4196 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4197 | AuthAllowsDefaultCredentialsTunnelServerClosesConnectionTwice) { |
| 4198 | HttpRequestInfo request; |
| 4199 | request.method = "GET"; |
| 4200 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4201 | request.traffic_annotation = |
| 4202 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4203 | |
| 4204 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4205 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4206 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4207 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4208 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4209 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4210 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4211 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4212 | mock_handler->set_allows_default_credentials(true); |
| 4213 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4214 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4215 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4216 | |
| 4217 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4218 | NetLog net_log; |
| 4219 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4220 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4221 | |
| 4222 | // Should try to establish tunnel. |
| 4223 | MockWrite data_writes1[] = { |
| 4224 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4225 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4226 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4227 | |
| 4228 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4229 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4230 | "Proxy-Connection: keep-alive\r\n" |
| 4231 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4232 | }; |
| 4233 | |
| 4234 | // The proxy responds to the connect with a 407, and then hangs up after the |
| 4235 | // second request is sent. |
| 4236 | MockRead data_reads1[] = { |
| 4237 | // No credentials. |
| 4238 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4239 | MockRead("Content-Length: 0\r\n"), |
| 4240 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 4241 | MockRead("Proxy-Authenticate: Mock\r\n\r\n"), |
| 4242 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4243 | }; |
| 4244 | |
| 4245 | // HttpNetworkTransaction sees a reused connection that was closed with |
| 4246 | // ERR_CONNECTION_CLOSED, realized it might have been a race, so retries the |
| 4247 | // request. |
| 4248 | MockWrite data_writes2[] = { |
| 4249 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4250 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4251 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4252 | }; |
| 4253 | |
| 4254 | // The proxy, having had more than enough of us, just hangs up. |
| 4255 | MockRead data_reads2[] = { |
| 4256 | // No credentials. |
| 4257 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED), |
| 4258 | }; |
| 4259 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4260 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4261 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4262 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4263 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 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_TRUE(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()); |
| 4279 | EXPECT_FALSE(response->auth_challenge); |
| 4280 | |
| 4281 | LoadTimingInfo load_timing_info; |
| 4282 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4283 | |
| 4284 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4285 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4286 | |
| 4287 | trans.reset(); |
| 4288 | session->CloseAllConnections(); |
| 4289 | } |
| 4290 | |
| 4291 | // Test a proxy auth scheme that allows default credentials and a proxy server |
| 4292 | // that hangs up when credentials are initially sent, and sends a challenge |
| 4293 | // again they are retried. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4294 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4295 | AuthAllowsDefaultCredentialsTunnelServerChallengesTwice) { |
| 4296 | HttpRequestInfo request; |
| 4297 | request.method = "GET"; |
| 4298 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4299 | request.traffic_annotation = |
| 4300 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4301 | |
| 4302 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4303 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4304 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4305 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4306 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4307 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4308 | auth_handler_factory->set_do_init_from_challenge(true); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4309 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4310 | mock_handler->set_allows_default_credentials(true); |
| 4311 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4312 | HttpAuth::AUTH_PROXY); |
| 4313 | // Add another handler for the second challenge. It supports default |
| 4314 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4315 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4316 | mock_handler->set_allows_default_credentials(true); |
| 4317 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4318 | HttpAuth::AUTH_PROXY); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 4319 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4320 | |
| 4321 | // Add NetLog just so can verify load timing information gets a NetLog ID. |
| 4322 | NetLog net_log; |
| 4323 | session_deps_.net_log = &net_log; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4324 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4325 | |
| 4326 | // Should try to establish tunnel. |
| 4327 | MockWrite data_writes1[] = { |
| 4328 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4329 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4330 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4331 | }; |
| 4332 | |
| 4333 | // The proxy responds to the connect with a 407, using a non-persistent |
| 4334 | // connection. |
| 4335 | MockRead data_reads1[] = { |
| 4336 | // No credentials. |
| 4337 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4338 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4339 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4340 | }; |
| 4341 | |
| 4342 | // Since the first connection was closed, need to establish another once given |
| 4343 | // credentials. |
| 4344 | MockWrite data_writes2[] = { |
| 4345 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4346 | "Host: www.example.org:443\r\n" |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4347 | "Proxy-Connection: keep-alive\r\n" |
| 4348 | "Proxy-Authorization: auth_token\r\n\r\n"), |
| 4349 | }; |
| 4350 | |
| 4351 | MockRead data_reads2[] = { |
| 4352 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 4353 | MockRead("Proxy-Authenticate: Mock\r\n"), |
| 4354 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 4355 | }; |
| 4356 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4357 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4358 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4359 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4360 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4361 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 4362 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4363 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4364 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4365 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4366 | |
| 4367 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 4368 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4369 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4370 | |
| 4371 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4372 | ASSERT_TRUE(response); |
| 4373 | ASSERT_TRUE(response->headers); |
| 4374 | EXPECT_EQ(407, response->headers->response_code()); |
| 4375 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4376 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4377 | EXPECT_FALSE(response->auth_challenge); |
| 4378 | |
| 4379 | LoadTimingInfo load_timing_info; |
| 4380 | EXPECT_FALSE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 4381 | |
| 4382 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4383 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
mmenke | 2a1781d | 2015-10-07 19:25:33 | [diff] [blame] | 4384 | response = trans->GetResponseInfo(); |
| 4385 | ASSERT_TRUE(response); |
| 4386 | ASSERT_TRUE(response->headers); |
| 4387 | EXPECT_EQ(407, response->headers->response_code()); |
| 4388 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4389 | EXPECT_TRUE(response->auth_challenge); |
| 4390 | |
| 4391 | trans.reset(); |
| 4392 | session->CloseAllConnections(); |
| 4393 | } |
| 4394 | |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4395 | // A more nuanced test than GenerateAuthToken test which asserts that |
| 4396 | // ERR_INVALID_AUTH_CREDENTIALS does not cause the auth scheme to be |
| 4397 | // unnecessarily invalidated, and that if the server co-operates, the |
| 4398 | // authentication handshake can continue with the same scheme but with a |
| 4399 | // different identity. |
| 4400 | TEST_F(HttpNetworkTransactionTest, NonPermanentGenerateAuthTokenError) { |
| 4401 | HttpRequestInfo request; |
| 4402 | request.method = "GET"; |
| 4403 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4404 | request.traffic_annotation = |
| 4405 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4406 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4407 | auto auth_handler_factory = std::make_unique<HttpAuthHandlerMock::Factory>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4408 | auth_handler_factory->set_do_init_from_challenge(true); |
| 4409 | |
| 4410 | // First handler. Uses default credentials, but barfs at generate auth token. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4411 | auto mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4412 | mock_handler->set_allows_default_credentials(true); |
| 4413 | mock_handler->set_allows_explicit_credentials(true); |
| 4414 | mock_handler->set_connection_based(true); |
| 4415 | mock_handler->SetGenerateExpectation(true, ERR_INVALID_AUTH_CREDENTIALS); |
| 4416 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4417 | HttpAuth::AUTH_SERVER); |
| 4418 | |
| 4419 | // Add another handler for the second challenge. It supports default |
| 4420 | // credentials, but they shouldn't be used, since they were already tried. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4421 | mock_handler = std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4422 | mock_handler->set_allows_default_credentials(true); |
| 4423 | mock_handler->set_allows_explicit_credentials(true); |
| 4424 | mock_handler->set_connection_based(true); |
| 4425 | auth_handler_factory->AddMockHandler(mock_handler.release(), |
| 4426 | HttpAuth::AUTH_SERVER); |
| 4427 | session_deps_.http_auth_handler_factory = std::move(auth_handler_factory); |
| 4428 | |
| 4429 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4430 | |
| 4431 | MockWrite data_writes1[] = { |
| 4432 | MockWrite("GET / HTTP/1.1\r\n" |
| 4433 | "Host: www.example.org\r\n" |
| 4434 | "Connection: keep-alive\r\n\r\n"), |
| 4435 | }; |
| 4436 | |
| 4437 | MockRead data_reads1[] = { |
| 4438 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4439 | "WWW-Authenticate: Mock\r\n" |
| 4440 | "Connection: keep-alive\r\n\r\n"), |
| 4441 | }; |
| 4442 | |
| 4443 | // Identical to data_writes1[]. The AuthHandler encounters a |
| 4444 | // ERR_INVALID_AUTH_CREDENTIALS during the GenerateAuthToken stage, so the |
| 4445 | // transaction procceds without an authorization header. |
| 4446 | MockWrite data_writes2[] = { |
| 4447 | MockWrite("GET / HTTP/1.1\r\n" |
| 4448 | "Host: www.example.org\r\n" |
| 4449 | "Connection: keep-alive\r\n\r\n"), |
| 4450 | }; |
| 4451 | |
| 4452 | MockRead data_reads2[] = { |
| 4453 | MockRead("HTTP/1.1 401 Authentication Required\r\n" |
| 4454 | "WWW-Authenticate: Mock\r\n" |
| 4455 | "Connection: keep-alive\r\n\r\n"), |
| 4456 | }; |
| 4457 | |
| 4458 | MockWrite data_writes3[] = { |
| 4459 | MockWrite("GET / HTTP/1.1\r\n" |
| 4460 | "Host: www.example.org\r\n" |
| 4461 | "Connection: keep-alive\r\n" |
| 4462 | "Authorization: auth_token\r\n\r\n"), |
| 4463 | }; |
| 4464 | |
| 4465 | MockRead data_reads3[] = { |
| 4466 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4467 | "Content-Length: 5\r\n" |
| 4468 | "Content-Type: text/plain\r\n" |
| 4469 | "Connection: keep-alive\r\n\r\n" |
| 4470 | "Hello"), |
| 4471 | }; |
| 4472 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4473 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4474 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 4475 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4476 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4477 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 4478 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4479 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4480 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 4481 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4482 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4483 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 4484 | |
| 4485 | TestCompletionCallback callback; |
| 4486 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4487 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4488 | |
| 4489 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4490 | ASSERT_TRUE(response); |
| 4491 | ASSERT_TRUE(response->headers); |
| 4492 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 4493 | |
| 4494 | // The following three tests assert that an authentication challenge was |
| 4495 | // received and that the stack is ready to respond to the challenge using |
| 4496 | // ambient credentials. |
| 4497 | EXPECT_EQ(401, response->headers->response_code()); |
| 4498 | EXPECT_TRUE(trans->IsReadyToRestartForAuth()); |
| 4499 | EXPECT_FALSE(response->auth_challenge); |
| 4500 | |
| 4501 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4502 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4503 | response = trans->GetResponseInfo(); |
| 4504 | ASSERT_TRUE(response); |
| 4505 | ASSERT_TRUE(response->headers); |
| 4506 | |
| 4507 | // The following three tests assert that an authentication challenge was |
| 4508 | // received and that the stack needs explicit credentials before it is ready |
| 4509 | // to respond to the challenge. |
| 4510 | EXPECT_EQ(401, response->headers->response_code()); |
| 4511 | EXPECT_FALSE(trans->IsReadyToRestartForAuth()); |
| 4512 | EXPECT_TRUE(response->auth_challenge); |
| 4513 | |
| 4514 | rv = trans->RestartWithAuth(AuthCredentials(), callback.callback()); |
| 4515 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4516 | response = trans->GetResponseInfo(); |
| 4517 | ASSERT_TRUE(response); |
| 4518 | ASSERT_TRUE(response->headers); |
| 4519 | EXPECT_EQ(200, response->headers->response_code()); |
| 4520 | |
| 4521 | trans.reset(); |
| 4522 | session->CloseAllConnections(); |
| 4523 | } |
| 4524 | |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4525 | // Proxy resolver that returns a proxy with the same host and port for different |
| 4526 | // schemes, based on the path of the URL being requests. |
| 4527 | class SameProxyWithDifferentSchemesProxyResolver : public ProxyResolver { |
| 4528 | public: |
| 4529 | SameProxyWithDifferentSchemesProxyResolver() {} |
| 4530 | ~SameProxyWithDifferentSchemesProxyResolver() override {} |
| 4531 | |
| 4532 | static std::string ProxyHostPortPairAsString() { return "proxy.test:10000"; } |
| 4533 | |
| 4534 | static HostPortPair ProxyHostPortPair() { |
| 4535 | return HostPortPair::FromString(ProxyHostPortPairAsString()); |
| 4536 | } |
| 4537 | |
| 4538 | // ProxyResolver implementation. |
| 4539 | int GetProxyForURL(const GURL& url, |
| 4540 | ProxyInfo* results, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4541 | CompletionOnceCallback callback, |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4542 | std::unique_ptr<Request>* request, |
| 4543 | const NetLogWithSource& /*net_log*/) override { |
| 4544 | *results = ProxyInfo(); |
Ramin Halavati | 921731ea | 2018-03-16 08:24:57 | [diff] [blame] | 4545 | results->set_traffic_annotation( |
| 4546 | MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS)); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4547 | if (url.path() == "/socks4") { |
| 4548 | results->UsePacString("SOCKS " + ProxyHostPortPairAsString()); |
| 4549 | return OK; |
| 4550 | } |
| 4551 | if (url.path() == "/socks5") { |
| 4552 | results->UsePacString("SOCKS5 " + ProxyHostPortPairAsString()); |
| 4553 | return OK; |
| 4554 | } |
| 4555 | if (url.path() == "/http") { |
| 4556 | results->UsePacString("PROXY " + ProxyHostPortPairAsString()); |
| 4557 | return OK; |
| 4558 | } |
| 4559 | if (url.path() == "/https") { |
| 4560 | results->UsePacString("HTTPS " + ProxyHostPortPairAsString()); |
| 4561 | return OK; |
| 4562 | } |
| 4563 | NOTREACHED(); |
| 4564 | return ERR_NOT_IMPLEMENTED; |
| 4565 | } |
| 4566 | |
| 4567 | private: |
| 4568 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolver); |
| 4569 | }; |
| 4570 | |
| 4571 | class SameProxyWithDifferentSchemesProxyResolverFactory |
| 4572 | : public ProxyResolverFactory { |
| 4573 | public: |
| 4574 | SameProxyWithDifferentSchemesProxyResolverFactory() |
| 4575 | : ProxyResolverFactory(false) {} |
| 4576 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4577 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 4578 | std::unique_ptr<ProxyResolver>* resolver, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 4579 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 4580 | std::unique_ptr<Request>* request) override { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4581 | *resolver = std::make_unique<SameProxyWithDifferentSchemesProxyResolver>(); |
| 4582 | return OK; |
| 4583 | } |
| 4584 | |
| 4585 | private: |
| 4586 | DISALLOW_COPY_AND_ASSIGN(SameProxyWithDifferentSchemesProxyResolverFactory); |
| 4587 | }; |
| 4588 | |
| 4589 | // Check that when different proxy schemes are all applied to a proxy at the |
| 4590 | // same address, the sonnections are not grouped together. i.e., a request to |
| 4591 | // foo.com using proxy.com as an HTTPS proxy won't use the same socket as a |
| 4592 | // request to foo.com using proxy.com as an HTTP proxy. |
| 4593 | TEST_F(HttpNetworkTransactionTest, SameDestinationForDifferentProxyTypes) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4594 | session_deps_.proxy_resolution_service = |
| 4595 | std::make_unique<ProxyResolutionService>( |
| 4596 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 4597 | ProxyConfig::CreateAutoDetect(), TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 4598 | std::make_unique<SameProxyWithDifferentSchemesProxyResolverFactory>(), |
| 4599 | nullptr); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4600 | |
| 4601 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
| 4602 | |
| 4603 | MockWrite socks_writes[] = { |
| 4604 | MockWrite(SYNCHRONOUS, kSOCKS4OkRequestLocalHostPort80, |
| 4605 | kSOCKS4OkRequestLocalHostPort80Length), |
| 4606 | MockWrite(SYNCHRONOUS, |
| 4607 | "GET /socks4 HTTP/1.1\r\n" |
| 4608 | "Host: test\r\n" |
| 4609 | "Connection: keep-alive\r\n\r\n"), |
| 4610 | }; |
| 4611 | MockRead socks_reads[] = { |
| 4612 | MockRead(SYNCHRONOUS, kSOCKS4OkReply, kSOCKS4OkReplyLength), |
| 4613 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4614 | "Connection: keep-alive\r\n" |
| 4615 | "Content-Length: 15\r\n\r\n" |
| 4616 | "SOCKS4 Response"), |
| 4617 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4618 | StaticSocketDataProvider socks_data(socks_reads, socks_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4619 | session_deps_.socket_factory->AddSocketDataProvider(&socks_data); |
| 4620 | |
| 4621 | const char kSOCKS5Request[] = { |
| 4622 | 0x05, // Version |
| 4623 | 0x01, // Command (CONNECT) |
| 4624 | 0x00, // Reserved |
| 4625 | 0x03, // Address type (DOMAINNAME) |
| 4626 | 0x04, // Length of domain (4) |
| 4627 | 't', 'e', 's', 't', // Domain string |
| 4628 | 0x00, 0x50, // 16-bit port (80) |
| 4629 | }; |
| 4630 | MockWrite socks5_writes[] = { |
| 4631 | MockWrite(ASYNC, kSOCKS5GreetRequest, kSOCKS5GreetRequestLength), |
| 4632 | MockWrite(ASYNC, kSOCKS5Request, arraysize(kSOCKS5Request)), |
| 4633 | MockWrite(SYNCHRONOUS, |
| 4634 | "GET /socks5 HTTP/1.1\r\n" |
| 4635 | "Host: test\r\n" |
| 4636 | "Connection: keep-alive\r\n\r\n"), |
| 4637 | }; |
| 4638 | MockRead socks5_reads[] = { |
| 4639 | MockRead(ASYNC, kSOCKS5GreetResponse, kSOCKS5GreetResponseLength), |
| 4640 | MockRead(ASYNC, kSOCKS5OkResponse, kSOCKS5OkResponseLength), |
| 4641 | MockRead("HTTP/1.0 200 OK\r\n" |
| 4642 | "Connection: keep-alive\r\n" |
| 4643 | "Content-Length: 15\r\n\r\n" |
| 4644 | "SOCKS5 Response"), |
| 4645 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4646 | StaticSocketDataProvider socks5_data(socks5_reads, socks5_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4647 | session_deps_.socket_factory->AddSocketDataProvider(&socks5_data); |
| 4648 | |
| 4649 | MockWrite http_writes[] = { |
| 4650 | MockWrite(SYNCHRONOUS, |
| 4651 | "GET http://test/http HTTP/1.1\r\n" |
| 4652 | "Host: test\r\n" |
| 4653 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4654 | }; |
| 4655 | MockRead http_reads[] = { |
| 4656 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4657 | "Proxy-Connection: keep-alive\r\n" |
| 4658 | "Content-Length: 13\r\n\r\n" |
| 4659 | "HTTP Response"), |
| 4660 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4661 | StaticSocketDataProvider http_data(http_reads, http_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4662 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 4663 | |
| 4664 | MockWrite https_writes[] = { |
| 4665 | MockWrite(SYNCHRONOUS, |
| 4666 | "GET http://test/https HTTP/1.1\r\n" |
| 4667 | "Host: test\r\n" |
| 4668 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 4669 | }; |
| 4670 | MockRead https_reads[] = { |
| 4671 | MockRead("HTTP/1.1 200 OK\r\n" |
| 4672 | "Proxy-Connection: keep-alive\r\n" |
| 4673 | "Content-Length: 14\r\n\r\n" |
| 4674 | "HTTPS Response"), |
| 4675 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4676 | StaticSocketDataProvider https_data(https_reads, https_writes); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4677 | session_deps_.socket_factory->AddSocketDataProvider(&https_data); |
| 4678 | SSLSocketDataProvider ssl(SYNCHRONOUS, OK); |
| 4679 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 4680 | |
| 4681 | struct TestCase { |
| 4682 | GURL url; |
| 4683 | std::string expected_response; |
| 4684 | // How many idle sockets there should be in the SOCKS proxy socket pool |
| 4685 | // after the test. |
| 4686 | int expected_idle_socks_sockets; |
| 4687 | // How many idle sockets there should be in the HTTP proxy socket pool after |
| 4688 | // the test. |
| 4689 | int expected_idle_http_sockets; |
| 4690 | } const kTestCases[] = { |
| 4691 | {GURL("http://test/socks4"), "SOCKS4 Response", 1, 0}, |
| 4692 | {GURL("http://test/socks5"), "SOCKS5 Response", 2, 0}, |
| 4693 | {GURL("http://test/http"), "HTTP Response", 2, 1}, |
| 4694 | {GURL("http://test/https"), "HTTPS Response", 2, 2}, |
| 4695 | }; |
| 4696 | |
| 4697 | for (const auto& test_case : kTestCases) { |
| 4698 | HttpRequestInfo request; |
| 4699 | request.method = "GET"; |
| 4700 | request.url = test_case.url; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4701 | request.traffic_annotation = |
| 4702 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 4703 | std::unique_ptr<HttpNetworkTransaction> trans = |
| 4704 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, |
| 4705 | session.get()); |
| 4706 | TestCompletionCallback callback; |
| 4707 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
| 4708 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 4709 | |
| 4710 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 4711 | ASSERT_TRUE(response); |
| 4712 | ASSERT_TRUE(response->headers); |
| 4713 | EXPECT_EQ(200, response->headers->response_code()); |
| 4714 | std::string response_data; |
| 4715 | EXPECT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 4716 | EXPECT_EQ(test_case.expected_response, response_data); |
| 4717 | |
| 4718 | // Return the socket to the socket pool, so can make sure it's not used for |
| 4719 | // the next requests. |
| 4720 | trans.reset(); |
| 4721 | base::RunLoop().RunUntilIdle(); |
| 4722 | |
| 4723 | // Check the number of idle sockets in the pool, to make sure that used |
| 4724 | // sockets are indeed being returned to the socket pool. If each request |
| 4725 | // doesn't return an idle socket to the pool, the test would incorrectly |
| 4726 | // pass. |
| 4727 | EXPECT_EQ( |
| 4728 | test_case.expected_idle_socks_sockets, |
| 4729 | session |
| 4730 | ->GetSocketPoolForSOCKSProxy( |
| 4731 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 4732 | SameProxyWithDifferentSchemesProxyResolver::ProxyHostPortPair()) |
| 4733 | ->IdleSocketCount()); |
| 4734 | EXPECT_EQ( |
| 4735 | test_case.expected_idle_http_sockets, |
| 4736 | session |
| 4737 | ->GetSocketPoolForHTTPProxy( |
| 4738 | HttpNetworkSession::NORMAL_SOCKET_POOL, |
| 4739 | SameProxyWithDifferentSchemesProxyResolver::ProxyHostPortPair()) |
| 4740 | ->IdleSocketCount()); |
| 4741 | } |
| 4742 | } |
| 4743 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4744 | // Test the load timing for HTTPS requests with an HTTP proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4745 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingNoPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4746 | HttpRequestInfo request1; |
| 4747 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4748 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4749 | request1.traffic_annotation = |
| 4750 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4751 | |
| 4752 | HttpRequestInfo request2; |
| 4753 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4754 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4755 | request2.traffic_annotation = |
| 4756 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4757 | |
| 4758 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4759 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4760 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4761 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4762 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4763 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4764 | |
| 4765 | // Since we have proxy, should try to establish tunnel. |
| 4766 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4767 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4768 | "Host: www.example.org:443\r\n" |
| 4769 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4770 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4771 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4772 | "Host: www.example.org\r\n" |
| 4773 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4774 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4775 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4776 | "Host: www.example.org\r\n" |
| 4777 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4778 | }; |
| 4779 | |
| 4780 | // The proxy responds to the connect with a 407, using a persistent |
| 4781 | // connection. |
| 4782 | MockRead data_reads1[] = { |
| 4783 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4784 | |
| 4785 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4786 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4787 | MockRead(SYNCHRONOUS, "1"), |
| 4788 | |
| 4789 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4790 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4791 | MockRead(SYNCHRONOUS, "22"), |
| 4792 | }; |
| 4793 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4794 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4795 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4796 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4797 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4798 | |
| 4799 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4800 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4801 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4802 | |
| 4803 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4804 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4805 | |
| 4806 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4807 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4808 | |
| 4809 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4810 | ASSERT_TRUE(response1); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4811 | EXPECT_TRUE(response1->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4812 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4813 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4814 | |
| 4815 | LoadTimingInfo load_timing_info1; |
| 4816 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4817 | TestLoadTimingNotReused(load_timing_info1, CONNECT_TIMING_HAS_SSL_TIMES); |
| 4818 | |
| 4819 | trans1.reset(); |
| 4820 | |
| 4821 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4822 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4823 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4824 | |
| 4825 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4826 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4827 | |
| 4828 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4829 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4830 | |
| 4831 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4832 | ASSERT_TRUE(response2); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 4833 | EXPECT_TRUE(response2->proxy_server.is_http()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4834 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4835 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4836 | |
| 4837 | LoadTimingInfo load_timing_info2; |
| 4838 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4839 | TestLoadTimingReused(load_timing_info2); |
| 4840 | |
| 4841 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4842 | |
| 4843 | trans2.reset(); |
| 4844 | session->CloseAllConnections(); |
| 4845 | } |
| 4846 | |
| 4847 | // 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] | 4848 | TEST_F(HttpNetworkTransactionTest, HttpProxyLoadTimingWithPacTwoRequests) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4849 | HttpRequestInfo request1; |
| 4850 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4851 | request1.url = GURL("https://www.example.org/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4852 | request1.traffic_annotation = |
| 4853 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4854 | |
| 4855 | HttpRequestInfo request2; |
| 4856 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4857 | request2.url = GURL("https://www.example.org/2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4858 | request2.traffic_annotation = |
| 4859 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4860 | |
| 4861 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 4862 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4863 | ProxyResolutionService::CreateFixedFromPacResult( |
| 4864 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4865 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4866 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4867 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4868 | |
| 4869 | // Since we have proxy, should try to establish tunnel. |
| 4870 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4871 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 4872 | "Host: www.example.org:443\r\n" |
| 4873 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4874 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4875 | MockWrite("GET /1 HTTP/1.1\r\n" |
| 4876 | "Host: www.example.org\r\n" |
| 4877 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4878 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 4879 | MockWrite("GET /2 HTTP/1.1\r\n" |
| 4880 | "Host: www.example.org\r\n" |
| 4881 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4882 | }; |
| 4883 | |
| 4884 | // The proxy responds to the connect with a 407, using a persistent |
| 4885 | // connection. |
| 4886 | MockRead data_reads1[] = { |
| 4887 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 4888 | |
| 4889 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4890 | MockRead("Content-Length: 1\r\n\r\n"), |
| 4891 | MockRead(SYNCHRONOUS, "1"), |
| 4892 | |
| 4893 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4894 | MockRead("Content-Length: 2\r\n\r\n"), |
| 4895 | MockRead(SYNCHRONOUS, "22"), |
| 4896 | }; |
| 4897 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4898 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4899 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4900 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4901 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4902 | |
| 4903 | TestCompletionCallback callback1; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4904 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4905 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4906 | |
| 4907 | int rv = trans1->Start(&request1, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4908 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4909 | |
| 4910 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4911 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4912 | |
| 4913 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4914 | ASSERT_TRUE(response1); |
| 4915 | ASSERT_TRUE(response1->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4916 | EXPECT_EQ(1, response1->headers->GetContentLength()); |
| 4917 | |
| 4918 | LoadTimingInfo load_timing_info1; |
| 4919 | EXPECT_TRUE(trans1->GetLoadTimingInfo(&load_timing_info1)); |
| 4920 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 4921 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 4922 | |
| 4923 | trans1.reset(); |
| 4924 | |
| 4925 | TestCompletionCallback callback2; |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 4926 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 4927 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4928 | |
| 4929 | rv = trans2->Start(&request2, callback2.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4930 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4931 | |
| 4932 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4933 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4934 | |
| 4935 | const HttpResponseInfo* response2 = trans2->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 4936 | ASSERT_TRUE(response2); |
| 4937 | ASSERT_TRUE(response2->headers); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 4938 | EXPECT_EQ(2, response2->headers->GetContentLength()); |
| 4939 | |
| 4940 | LoadTimingInfo load_timing_info2; |
| 4941 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 4942 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 4943 | |
| 4944 | EXPECT_EQ(load_timing_info1.socket_log_id, load_timing_info2.socket_log_id); |
| 4945 | |
| 4946 | trans2.reset(); |
| 4947 | session->CloseAllConnections(); |
| 4948 | } |
| 4949 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4950 | // Test a simple get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 4951 | TEST_F(HttpNetworkTransactionTest, HttpsProxyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4952 | HttpRequestInfo request; |
| 4953 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4954 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 4955 | request.traffic_annotation = |
| 4956 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 4957 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4958 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 4959 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 4960 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 4961 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4962 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 4963 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4964 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4965 | // Since we have proxy, should use full url |
| 4966 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 4967 | MockWrite( |
| 4968 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 4969 | "Host: www.example.org\r\n" |
| 4970 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4971 | }; |
| 4972 | |
| 4973 | MockRead data_reads1[] = { |
| 4974 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 4975 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 4976 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4977 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4978 | }; |
| 4979 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 4980 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4981 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 4982 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 4983 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4984 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 4985 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4986 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4987 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 4988 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4989 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4990 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4991 | |
| 4992 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 4993 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 4994 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4995 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 4996 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 4997 | TestLoadTimingNotReused(load_timing_info, |
| 4998 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 4999 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5000 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5001 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5002 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5003 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5004 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5005 | EXPECT_EQ(200, response->headers->response_code()); |
| 5006 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5007 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5008 | |
| 5009 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5010 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5011 | } |
| 5012 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5013 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5014 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGet) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5015 | HttpRequestInfo request; |
| 5016 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5017 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5018 | request.traffic_annotation = |
| 5019 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5020 | |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5021 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5022 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5023 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5024 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5025 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5026 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5027 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5028 | // fetch http://www.example.org/ via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5029 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5030 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5031 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5032 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5033 | spdy::SpdySerializedFrame resp( |
| 5034 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 5035 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5036 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5037 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5038 | }; |
| 5039 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5040 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5041 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5042 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5043 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5044 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5045 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5046 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5047 | TestCompletionCallback callback1; |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5048 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5049 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5050 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5051 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5052 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5053 | |
| 5054 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5055 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5056 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5057 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5058 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5059 | TestLoadTimingNotReused(load_timing_info, |
| 5060 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5061 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5062 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5063 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 5064 | EXPECT_TRUE(response->proxy_server.is_https()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5065 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5066 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5067 | |
| 5068 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5069 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5070 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | 7642b5ae | 2010-09-01 20:55:17 | [diff] [blame] | 5071 | } |
| 5072 | |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5073 | // Verifies that a session which races and wins against the owning transaction |
| 5074 | // (completing prior to host resolution), doesn't fail the transaction. |
| 5075 | // Regression test for crbug.com/334413. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5076 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithSessionRace) { |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5077 | HttpRequestInfo request; |
| 5078 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5079 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5080 | request.traffic_annotation = |
| 5081 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5082 | |
| 5083 | // Configure SPDY proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5084 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5085 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5086 | BoundTestNetLog log; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5087 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5088 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5089 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5090 | // Fetch http://www.example.org/ through the SPDY proxy. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5091 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5092 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5093 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5094 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5095 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 5096 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5097 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5098 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5099 | }; |
| 5100 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5101 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5102 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 5103 | |
| 5104 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5105 | ssl.next_proto = kProtoHTTP2; |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5106 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 5107 | |
| 5108 | TestCompletionCallback callback1; |
| 5109 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5110 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5111 | |
| 5112 | // Stall the hostname resolution begun by the transaction. |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5113 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5114 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5115 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5116 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5117 | |
| 5118 | // Race a session to the proxy, which completes first. |
| 5119 | session_deps_.host_resolver->set_ondemand_mode(false); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 5120 | SpdySessionKey key(HostPortPair("proxy", 70), ProxyServer::Direct(), |
| 5121 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5122 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 5123 | CreateSpdySession(session.get(), key, log.bound()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5124 | |
| 5125 | // Unstall the resolution begun by the transaction. |
| 5126 | session_deps_.host_resolver->set_ondemand_mode(true); |
| 5127 | session_deps_.host_resolver->ResolveAllPending(); |
| 5128 | |
| 5129 | EXPECT_FALSE(callback1.have_result()); |
| 5130 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5131 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5132 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5133 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5134 | ASSERT_TRUE(response); |
| 5135 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5136 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5137 | |
| 5138 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5139 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 1c17385 | 2014-06-19 12:51:50 | [diff] [blame] | 5140 | EXPECT_EQ(kUploadData, response_data); |
| 5141 | } |
| 5142 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5143 | // Test a SPDY get through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5144 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyGetWithProxyAuth) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5145 | HttpRequestInfo request; |
| 5146 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5147 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5148 | request.traffic_annotation = |
| 5149 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5150 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5151 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5152 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5153 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5154 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5155 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5156 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5157 | |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5158 | // The first request will be a bare GET, the second request will be a |
| 5159 | // GET with a Proxy-Authorization header. |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 5160 | spdy_util_.set_default_url(request.url); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5161 | spdy::SpdySerializedFrame req_get( |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5162 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5163 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5164 | const char* const kExtraAuthorizationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5165 | "proxy-authorization", "Basic Zm9vOmJhcg==" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5166 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5167 | spdy::SpdySerializedFrame req_get_authorization(spdy_util_.ConstructSpdyGet( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5168 | kExtraAuthorizationHeaders, arraysize(kExtraAuthorizationHeaders) / 2, 3, |
Bence Béky | 27ad0a1 | 2018-02-08 00:35:48 | [diff] [blame] | 5169 | LOWEST)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5170 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5171 | CreateMockWrite(req_get, 0), CreateMockWrite(req_get_authorization, 3), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5172 | }; |
| 5173 | |
| 5174 | // The first response is a 407 proxy authentication challenge, and the second |
| 5175 | // response will be a 200 response since the second request includes a valid |
| 5176 | // Authorization header. |
| 5177 | const char* const kExtraAuthenticationHeaders[] = { |
[email protected] | cdf8f7e7 | 2013-05-23 10:56:46 | [diff] [blame] | 5178 | "proxy-authenticate", "Basic realm=\"MyRealm1\"" |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5179 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5180 | spdy::SpdySerializedFrame resp_authentication( |
| 5181 | spdy_util_.ConstructSpdyReplyError( |
| 5182 | "407", kExtraAuthenticationHeaders, |
| 5183 | arraysize(kExtraAuthenticationHeaders) / 2, 1)); |
| 5184 | spdy::SpdySerializedFrame body_authentication( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5185 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5186 | spdy::SpdySerializedFrame resp_data( |
| 5187 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 5188 | spdy::SpdySerializedFrame body_data( |
| 5189 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5190 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5191 | CreateMockRead(resp_authentication, 1), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5192 | CreateMockRead(body_authentication, 2, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5193 | CreateMockRead(resp_data, 4), |
| 5194 | CreateMockRead(body_data, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5195 | MockRead(ASYNC, 0, 6), |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5196 | }; |
| 5197 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5198 | SequencedSocketData data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5199 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5200 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5201 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5202 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5203 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5204 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5205 | TestCompletionCallback callback1; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5206 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5207 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5208 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5209 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5210 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5211 | |
| 5212 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5213 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5214 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5215 | const HttpResponseInfo* const response = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5216 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5217 | ASSERT_TRUE(response); |
| 5218 | ASSERT_TRUE(response->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5219 | EXPECT_EQ(407, response->headers->response_code()); |
| 5220 | EXPECT_TRUE(response->was_fetched_via_spdy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5221 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5222 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5223 | TestCompletionCallback callback2; |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5224 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5225 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5226 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5227 | |
| 5228 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5229 | EXPECT_THAT(rv, IsOk()); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5230 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5231 | const HttpResponseInfo* const response_restart = trans.GetResponseInfo(); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5232 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5233 | ASSERT_TRUE(response_restart); |
| 5234 | ASSERT_TRUE(response_restart->headers); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5235 | EXPECT_EQ(200, response_restart->headers->response_code()); |
| 5236 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5237 | EXPECT_FALSE(response_restart->auth_challenge); |
[email protected] | dc7bd1c5 | 2010-11-12 00:01:13 | [diff] [blame] | 5238 | } |
| 5239 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5240 | // Test a SPDY CONNECT through an HTTPS Proxy to an HTTPS (non-SPDY) Server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5241 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectHttps) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5242 | HttpRequestInfo request; |
| 5243 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5244 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5245 | request.traffic_annotation = |
| 5246 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5247 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5248 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5249 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5250 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5251 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5252 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5253 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5254 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5255 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5256 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5257 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5258 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5259 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5260 | // fetch https://www.example.org/ via HTTP |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5261 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5262 | const char get[] = |
| 5263 | "GET / HTTP/1.1\r\n" |
| 5264 | "Host: www.example.org\r\n" |
| 5265 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5266 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5267 | spdy_util_.ConstructSpdyDataFrame(1, get, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5268 | spdy::SpdySerializedFrame conn_resp( |
| 5269 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5270 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 5271 | "Content-Length: 10\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5272 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5273 | spdy_util_.ConstructSpdyDataFrame(1, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5274 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5275 | spdy_util_.ConstructSpdyDataFrame(1, "1234567890", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5276 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5277 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5278 | |
| 5279 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5280 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5281 | CreateMockWrite(window_update, 6), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5282 | }; |
| 5283 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5284 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5285 | CreateMockRead(conn_resp, 1, ASYNC), |
| 5286 | CreateMockRead(wrapped_get_resp, 3, ASYNC), |
| 5287 | CreateMockRead(wrapped_body, 4, ASYNC), |
| 5288 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5289 | MockRead(ASYNC, 0, 7), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5290 | }; |
| 5291 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5292 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5293 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5294 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5295 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5296 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5297 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5298 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5299 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5300 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5301 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5302 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5303 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5304 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5305 | |
| 5306 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5307 | ASSERT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5308 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5309 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5310 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5311 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5312 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5313 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5314 | ASSERT_TRUE(response); |
| 5315 | ASSERT_TRUE(response->headers); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5316 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5317 | |
| 5318 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5319 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5320 | EXPECT_EQ("1234567890", response_data); |
| 5321 | } |
| 5322 | |
| 5323 | // Test a SPDY CONNECT through an HTTPS Proxy to a SPDY server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5324 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectSpdy) { |
| 5325 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5326 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5327 | HttpRequestInfo request; |
| 5328 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5329 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5330 | request.traffic_annotation = |
| 5331 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5332 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5333 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5334 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5335 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5336 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5337 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5338 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5339 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5340 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5341 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5342 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5343 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5344 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
| 5345 | // fetch https://www.example.org/ via SPDY |
| 5346 | const char kMyUrl[] = "https://www.example.org/"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5347 | spdy::SpdySerializedFrame get( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 5348 | spdy_util_wrapped.ConstructSpdyGet(kMyUrl, 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5349 | spdy::SpdySerializedFrame wrapped_get( |
| 5350 | spdy_util_.ConstructWrappedSpdyFrame(get, 1)); |
| 5351 | spdy::SpdySerializedFrame conn_resp( |
| 5352 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 5353 | spdy::SpdySerializedFrame get_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5354 | spdy_util_wrapped.ConstructSpdyGetReply(NULL, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5355 | spdy::SpdySerializedFrame wrapped_get_resp( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5356 | spdy_util_.ConstructWrappedSpdyFrame(get_resp, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5357 | spdy::SpdySerializedFrame body( |
| 5358 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 5359 | spdy::SpdySerializedFrame wrapped_body( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5360 | spdy_util_.ConstructWrappedSpdyFrame(body, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5361 | spdy::SpdySerializedFrame window_update_get_resp( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5362 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp.size())); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5363 | spdy::SpdySerializedFrame window_update_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5364 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_body.size())); |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5365 | |
| 5366 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5367 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_get, 2), |
| 5368 | CreateMockWrite(window_update_get_resp, 6), |
| 5369 | CreateMockWrite(window_update_body, 7), |
[email protected] | 8d2f701 | 2012-02-16 00:08:04 | [diff] [blame] | 5370 | }; |
| 5371 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5372 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5373 | CreateMockRead(conn_resp, 1, ASYNC), |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5374 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5375 | CreateMockRead(wrapped_get_resp, 4, ASYNC), |
| 5376 | CreateMockRead(wrapped_body, 5, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 5377 | MockRead(ASYNC, 0, 8), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5378 | }; |
| 5379 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5380 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5381 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5382 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5383 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5384 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5385 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5386 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5387 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5388 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5389 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5390 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5391 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5392 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5393 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5394 | |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5395 | // Allow the SpdyProxyClientSocket's write callback to complete. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 5396 | base::RunLoop().RunUntilIdle(); |
rch | 3232084 | 2015-05-16 15:57:09 | [diff] [blame] | 5397 | // Now allow the read of the response to complete. |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 5398 | spdy_data.Resume(); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5399 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5400 | EXPECT_THAT(rv, IsOk()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5401 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5402 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5403 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5404 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5405 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5406 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5407 | ASSERT_TRUE(response); |
| 5408 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5409 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5410 | |
| 5411 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5412 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5413 | EXPECT_EQ(kUploadData, response_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5414 | } |
| 5415 | |
| 5416 | // Test a SPDY CONNECT failure through an HTTPS Proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5417 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyConnectFailure) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5418 | HttpRequestInfo request; |
| 5419 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5420 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5421 | request.traffic_annotation = |
| 5422 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5423 | |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5424 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5425 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5426 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5427 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5428 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5429 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5430 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5431 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5432 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5433 | // CONNECT to www.example.org:443 via SPDY |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5434 | spdy::SpdySerializedFrame connect(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5435 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5436 | spdy::SpdySerializedFrame get( |
| 5437 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5438 | |
| 5439 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5440 | CreateMockWrite(connect, 0), CreateMockWrite(get, 2), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5441 | }; |
| 5442 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5443 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError(1)); |
| 5444 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5445 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5446 | CreateMockRead(resp, 1, ASYNC), MockRead(ASYNC, 0, 3), |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5447 | }; |
| 5448 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5449 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5450 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5451 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5452 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5453 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5454 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5455 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5456 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5457 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5458 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5459 | TestCompletionCallback callback1; |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5460 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5461 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5462 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5463 | |
| 5464 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5465 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5466 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 5467 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | d9da5fe | 2010-10-13 22:37:16 | [diff] [blame] | 5468 | } |
| 5469 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5470 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5471 | // HTTPS Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5472 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5473 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsTwoServers) { |
| 5474 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5475 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5476 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5477 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5478 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5479 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5480 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5481 | |
| 5482 | HttpRequestInfo request1; |
| 5483 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5484 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5485 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5486 | request1.traffic_annotation = |
| 5487 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5488 | |
| 5489 | HttpRequestInfo request2; |
| 5490 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5491 | request2.url = GURL("https://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5492 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5493 | request2.traffic_annotation = |
| 5494 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5495 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5496 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5497 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5498 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5499 | spdy::SpdySerializedFrame conn_resp1( |
| 5500 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5501 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5502 | // Fetch https://www.example.org/ via HTTP. |
| 5503 | const char get1[] = |
| 5504 | "GET / HTTP/1.1\r\n" |
| 5505 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5506 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5507 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5508 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5509 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5510 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5511 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5512 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5513 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5514 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5515 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5516 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5517 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5518 | // CONNECT to mail.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5519 | spdy::SpdyHeaderBlock connect2_block; |
| 5520 | connect2_block[spdy::kHttp2MethodHeader] = "CONNECT"; |
| 5521 | connect2_block[spdy::kHttp2AuthorityHeader] = "mail.example.org:443"; |
| 5522 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyHeaders( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5523 | 3, std::move(connect2_block), LOWEST, false)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 5524 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5525 | spdy::SpdySerializedFrame conn_resp2( |
| 5526 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5527 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5528 | // Fetch https://mail.example.org/ via HTTP. |
| 5529 | const char get2[] = |
| 5530 | "GET / HTTP/1.1\r\n" |
| 5531 | "Host: mail.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5532 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5533 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5534 | spdy_util_.ConstructSpdyDataFrame(3, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5535 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5536 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5537 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5538 | spdy_util_.ConstructSpdyDataFrame(3, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5539 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5540 | spdy_util_.ConstructSpdyDataFrame(3, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5541 | |
| 5542 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5543 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5544 | CreateMockWrite(connect2, 5), CreateMockWrite(wrapped_get2, 7), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5545 | }; |
| 5546 | |
| 5547 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5548 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5549 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
| 5550 | CreateMockRead(wrapped_body1, 4, ASYNC), |
| 5551 | CreateMockRead(conn_resp2, 6, ASYNC), |
| 5552 | CreateMockRead(wrapped_get_resp2, 8, ASYNC), |
| 5553 | CreateMockRead(wrapped_body2, 9, ASYNC), |
| 5554 | MockRead(ASYNC, 0, 10), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5555 | }; |
| 5556 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5557 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5558 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5559 | |
| 5560 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5561 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5562 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5563 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5564 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5565 | SSLSocketDataProvider ssl3(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5566 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5567 | |
| 5568 | TestCompletionCallback callback; |
| 5569 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5570 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5571 | int rv = trans.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5572 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5573 | |
| 5574 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5575 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5576 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5577 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5578 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5579 | ASSERT_TRUE(response); |
| 5580 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5581 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5582 | |
| 5583 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 5584 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5585 | rv = trans.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5586 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5587 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5588 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5589 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5590 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5591 | |
| 5592 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5593 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5594 | // Even though the SPDY connection is reused, a new tunnelled connection has |
| 5595 | // to be created, so the socket's load timing looks like a fresh connection. |
| 5596 | TestLoadTimingNotReused(load_timing_info2, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5597 | |
| 5598 | // The requests should have different IDs, since they each are using their own |
| 5599 | // separate stream. |
| 5600 | EXPECT_NE(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5601 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5602 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5603 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5604 | } |
| 5605 | |
| 5606 | // Test load timing in the case of two HTTPS (non-SPDY) requests through a SPDY |
| 5607 | // HTTPS Proxy to the same server. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5608 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5609 | HttpsProxySpdyConnectHttpsLoadTimingTwoRequestsSameServer) { |
| 5610 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5611 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5612 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5613 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5614 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5615 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5616 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5617 | |
| 5618 | HttpRequestInfo request1; |
| 5619 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5620 | request1.url = GURL("https://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5621 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5622 | request1.traffic_annotation = |
| 5623 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5624 | |
| 5625 | HttpRequestInfo request2; |
| 5626 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5627 | request2.url = GURL("https://www.example.org/2"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5628 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5629 | request2.traffic_annotation = |
| 5630 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5631 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5632 | // CONNECT to www.example.org:443 via SPDY. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5633 | spdy::SpdySerializedFrame connect1(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5634 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5635 | spdy::SpdySerializedFrame conn_resp1( |
| 5636 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5637 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5638 | // Fetch https://www.example.org/ via HTTP. |
| 5639 | const char get1[] = |
| 5640 | "GET / HTTP/1.1\r\n" |
| 5641 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5642 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5643 | spdy::SpdySerializedFrame wrapped_get1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5644 | spdy_util_.ConstructSpdyDataFrame(1, get1, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5645 | const char resp1[] = "HTTP/1.1 200 OK\r\n" |
| 5646 | "Content-Length: 1\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5647 | spdy::SpdySerializedFrame wrapped_get_resp1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5648 | spdy_util_.ConstructSpdyDataFrame(1, resp1, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5649 | spdy::SpdySerializedFrame wrapped_body1( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5650 | spdy_util_.ConstructSpdyDataFrame(1, "1", false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5651 | spdy::SpdySerializedFrame window_update( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5652 | spdy_util_.ConstructSpdyWindowUpdate(1, wrapped_get_resp1.size())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5653 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5654 | // Fetch https://www.example.org/2 via HTTP. |
| 5655 | const char get2[] = |
| 5656 | "GET /2 HTTP/1.1\r\n" |
| 5657 | "Host: www.example.org\r\n" |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5658 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5659 | spdy::SpdySerializedFrame wrapped_get2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5660 | spdy_util_.ConstructSpdyDataFrame(1, get2, false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5661 | const char resp2[] = "HTTP/1.1 200 OK\r\n" |
| 5662 | "Content-Length: 2\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5663 | spdy::SpdySerializedFrame wrapped_get_resp2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5664 | spdy_util_.ConstructSpdyDataFrame(1, resp2, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5665 | spdy::SpdySerializedFrame wrapped_body2( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 5666 | spdy_util_.ConstructSpdyDataFrame(1, "22", false)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5667 | |
| 5668 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5669 | CreateMockWrite(connect1, 0), CreateMockWrite(wrapped_get1, 2), |
| 5670 | CreateMockWrite(wrapped_get2, 5), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5671 | }; |
| 5672 | |
| 5673 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5674 | CreateMockRead(conn_resp1, 1, ASYNC), |
| 5675 | CreateMockRead(wrapped_get_resp1, 3, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5676 | CreateMockRead(wrapped_body1, 4, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5677 | CreateMockRead(wrapped_get_resp2, 6, ASYNC), |
bnc | eb9aa711 | 2017-01-05 01:03:46 | [diff] [blame] | 5678 | CreateMockRead(wrapped_body2, 7, SYNCHRONOUS), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5679 | MockRead(ASYNC, 0, 8), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5680 | }; |
| 5681 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5682 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5683 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5684 | |
| 5685 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5686 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5687 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5688 | SSLSocketDataProvider ssl2(ASYNC, OK); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5689 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5690 | |
| 5691 | TestCompletionCallback callback; |
| 5692 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5693 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5694 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5695 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5696 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5697 | |
| 5698 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5699 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5700 | |
| 5701 | LoadTimingInfo load_timing_info; |
| 5702 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5703 | TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_SSL_TIMES); |
| 5704 | |
| 5705 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5706 | ASSERT_TRUE(response); |
| 5707 | ASSERT_TRUE(response->headers); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5708 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 5709 | |
| 5710 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 5711 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5712 | EXPECT_EQ(1, trans->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5713 | trans.reset(); |
| 5714 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5715 | auto trans2 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5716 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5717 | rv = trans2->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5718 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5719 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5720 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5721 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5722 | |
| 5723 | LoadTimingInfo load_timing_info2; |
| 5724 | EXPECT_TRUE(trans2->GetLoadTimingInfo(&load_timing_info2)); |
| 5725 | TestLoadTimingReused(load_timing_info2); |
| 5726 | |
| 5727 | // The requests should have the same ID. |
| 5728 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5729 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 5730 | EXPECT_EQ(2, trans2->Read(buf.get(), 256, callback.callback())); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5731 | } |
| 5732 | |
| 5733 | // Test load timing in the case of of two HTTP requests through a SPDY HTTPS |
| 5734 | // Proxy to different servers. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5735 | TEST_F(HttpNetworkTransactionTest, HttpsProxySpdyLoadTimingTwoHttpRequests) { |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5736 | // Configure against https proxy server "proxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5737 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5738 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5739 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5740 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5741 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5742 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5743 | |
| 5744 | HttpRequestInfo request1; |
| 5745 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5746 | request1.url = GURL("http://www.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5747 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5748 | request1.traffic_annotation = |
| 5749 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5750 | |
| 5751 | HttpRequestInfo request2; |
| 5752 | request2.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5753 | request2.url = GURL("http://mail.example.org/"); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5754 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5755 | request2.traffic_annotation = |
| 5756 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5757 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5758 | // http://www.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5759 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5760 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5761 | spdy::SpdySerializedFrame get1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5762 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5763 | spdy::SpdySerializedFrame get_resp1( |
| 5764 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 5765 | spdy::SpdySerializedFrame body1( |
| 5766 | spdy_util_.ConstructSpdyDataFrame(1, "1", true)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 5767 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5768 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5769 | // http://mail.example.org/ |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5770 | spdy::SpdyHeaderBlock headers2( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5771 | spdy_util_.ConstructGetHeaderBlockForProxy("http://mail.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5772 | spdy::SpdySerializedFrame get2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 5773 | spdy_util_.ConstructSpdyHeaders(3, std::move(headers2), LOWEST, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 5774 | spdy::SpdySerializedFrame get_resp2( |
| 5775 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 5776 | spdy::SpdySerializedFrame body2( |
| 5777 | spdy_util_.ConstructSpdyDataFrame(3, "22", true)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5778 | |
| 5779 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5780 | CreateMockWrite(get1, 0), CreateMockWrite(get2, 3), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5781 | }; |
| 5782 | |
| 5783 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 5784 | CreateMockRead(get_resp1, 1, ASYNC), |
| 5785 | CreateMockRead(body1, 2, ASYNC), |
| 5786 | CreateMockRead(get_resp2, 4, ASYNC), |
| 5787 | CreateMockRead(body2, 5, ASYNC), |
| 5788 | MockRead(ASYNC, 0, 6), |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5789 | }; |
| 5790 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5791 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5792 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5793 | |
| 5794 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 5795 | ssl.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5796 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5797 | |
| 5798 | TestCompletionCallback callback; |
| 5799 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 5800 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 5801 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5802 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5803 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5804 | |
| 5805 | LoadTimingInfo load_timing_info; |
| 5806 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 5807 | TestLoadTimingNotReused(load_timing_info, |
| 5808 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5809 | |
| 5810 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5811 | ASSERT_TRUE(response); |
| 5812 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 5813 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5814 | |
| 5815 | std::string response_data; |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 5816 | scoped_refptr<IOBuffer> buf = base::MakeRefCounted<IOBuffer>(256); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5817 | rv = trans->Read(buf.get(), 256, callback.callback()); |
| 5818 | EXPECT_EQ(1, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5819 | // Delete the first request, so the second one can reuse the socket. |
| 5820 | trans.reset(); |
| 5821 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5822 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5823 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5824 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5825 | |
| 5826 | LoadTimingInfo load_timing_info2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5827 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5828 | TestLoadTimingReused(load_timing_info2); |
| 5829 | |
| 5830 | // The requests should have the same ID. |
| 5831 | EXPECT_EQ(load_timing_info.socket_log_id, load_timing_info2.socket_log_id); |
| 5832 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5833 | rv = trans2.Read(buf.get(), 256, callback.callback()); |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 5834 | EXPECT_EQ(2, callback.GetResult(rv)); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 5835 | } |
| 5836 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5837 | // Test the challenge-response-retry sequence through an HTTPS Proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5838 | TEST_F(HttpNetworkTransactionTest, HttpsProxyAuthRetry) { |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5839 | HttpRequestInfo request; |
| 5840 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5841 | request.url = GURL("http://www.example.org/"); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5842 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 5843 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5844 | request.traffic_annotation = |
| 5845 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5846 | |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 5847 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5848 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5849 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 5850 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5851 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5852 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5853 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5854 | // Since we have proxy, should use full url |
| 5855 | MockWrite data_writes1[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5856 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5857 | "Host: www.example.org\r\n" |
| 5858 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5859 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5860 | // After calling trans.RestartWithAuth(), this is the request we should |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5861 | // be issuing -- the final header line contains the credentials. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5862 | MockWrite("GET http://www.example.org/ HTTP/1.1\r\n" |
| 5863 | "Host: www.example.org\r\n" |
| 5864 | "Proxy-Connection: keep-alive\r\n" |
| 5865 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5866 | }; |
| 5867 | |
| 5868 | // The proxy responds to the GET with a 407, using a persistent |
| 5869 | // connection. |
| 5870 | MockRead data_reads1[] = { |
| 5871 | // No credentials. |
| 5872 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 5873 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 5874 | MockRead("Proxy-Connection: keep-alive\r\n"), |
| 5875 | MockRead("Content-Length: 0\r\n\r\n"), |
| 5876 | |
| 5877 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 5878 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 5879 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5880 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5881 | }; |
| 5882 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5883 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5884 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 5885 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5886 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5887 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5888 | TestCompletionCallback callback1; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5889 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5890 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5891 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5892 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5893 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5894 | |
| 5895 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5896 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5897 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5898 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5899 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5900 | TestLoadTimingNotReused(load_timing_info, |
| 5901 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 5902 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5903 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5904 | ASSERT_TRUE(response); |
| 5905 | ASSERT_TRUE(response->headers); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5906 | EXPECT_EQ(407, response->headers->response_code()); |
| 5907 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 5908 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5909 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5910 | TestCompletionCallback callback2; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5911 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5912 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5913 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5914 | |
| 5915 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5916 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5917 | |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5918 | load_timing_info = LoadTimingInfo(); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5919 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 58e32bb | 2013-01-21 18:23:25 | [diff] [blame] | 5920 | // Retrying with HTTP AUTH is considered to be reusing a socket. |
| 5921 | TestLoadTimingReused(load_timing_info); |
| 5922 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5923 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5924 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5925 | |
| 5926 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 5927 | EXPECT_EQ(200, response->headers->response_code()); |
| 5928 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 5929 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 5930 | |
| 5931 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 5932 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 5933 | } |
| 5934 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5935 | void HttpNetworkTransactionTest::ConnectStatusHelperWithExpectedStatus( |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5936 | const MockRead& status, int expected_status) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5937 | HttpRequestInfo request; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5938 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 5939 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 5940 | request.traffic_annotation = |
| 5941 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5942 | |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5943 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 5944 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 5945 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 5946 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 5947 | |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5948 | // Since we have proxy, should try to establish tunnel. |
| 5949 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 5950 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 5951 | "Host: www.example.org:443\r\n" |
| 5952 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5953 | }; |
| 5954 | |
| 5955 | MockRead data_reads[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 5956 | status, MockRead("Content-Length: 10\r\n\r\n"), |
| 5957 | // No response body because the test stops reading here. |
| 5958 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5959 | }; |
| 5960 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 5961 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 5962 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5963 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 5964 | TestCompletionCallback callback; |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5965 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 5966 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 5967 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 5968 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 5969 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5970 | |
| 5971 | rv = callback.WaitForResult(); |
| 5972 | EXPECT_EQ(expected_status, rv); |
| 5973 | } |
| 5974 | |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 5975 | void HttpNetworkTransactionTest::ConnectStatusHelper( |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 5976 | const MockRead& status) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5977 | ConnectStatusHelperWithExpectedStatus( |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 5978 | status, ERR_TUNNEL_CONNECTION_FAILED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5979 | } |
| 5980 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5981 | TEST_F(HttpNetworkTransactionTest, ConnectStatus100) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5982 | ConnectStatusHelper(MockRead("HTTP/1.1 100 Continue\r\n")); |
| 5983 | } |
| 5984 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5985 | TEST_F(HttpNetworkTransactionTest, ConnectStatus101) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5986 | ConnectStatusHelper(MockRead("HTTP/1.1 101 Switching Protocols\r\n")); |
| 5987 | } |
| 5988 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5989 | TEST_F(HttpNetworkTransactionTest, ConnectStatus201) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5990 | ConnectStatusHelper(MockRead("HTTP/1.1 201 Created\r\n")); |
| 5991 | } |
| 5992 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5993 | TEST_F(HttpNetworkTransactionTest, ConnectStatus202) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5994 | ConnectStatusHelper(MockRead("HTTP/1.1 202 Accepted\r\n")); |
| 5995 | } |
| 5996 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 5997 | TEST_F(HttpNetworkTransactionTest, ConnectStatus203) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 5998 | ConnectStatusHelper( |
| 5999 | MockRead("HTTP/1.1 203 Non-Authoritative Information\r\n")); |
| 6000 | } |
| 6001 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6002 | TEST_F(HttpNetworkTransactionTest, ConnectStatus204) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6003 | ConnectStatusHelper(MockRead("HTTP/1.1 204 No Content\r\n")); |
| 6004 | } |
| 6005 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6006 | TEST_F(HttpNetworkTransactionTest, ConnectStatus205) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6007 | ConnectStatusHelper(MockRead("HTTP/1.1 205 Reset Content\r\n")); |
| 6008 | } |
| 6009 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6010 | TEST_F(HttpNetworkTransactionTest, ConnectStatus206) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6011 | ConnectStatusHelper(MockRead("HTTP/1.1 206 Partial Content\r\n")); |
| 6012 | } |
| 6013 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6014 | TEST_F(HttpNetworkTransactionTest, ConnectStatus300) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6015 | ConnectStatusHelper(MockRead("HTTP/1.1 300 Multiple Choices\r\n")); |
| 6016 | } |
| 6017 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6018 | TEST_F(HttpNetworkTransactionTest, ConnectStatus301) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6019 | ConnectStatusHelper(MockRead("HTTP/1.1 301 Moved Permanently\r\n")); |
| 6020 | } |
| 6021 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6022 | TEST_F(HttpNetworkTransactionTest, ConnectStatus302) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6023 | ConnectStatusHelper(MockRead("HTTP/1.1 302 Found\r\n")); |
| 6024 | } |
| 6025 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6026 | TEST_F(HttpNetworkTransactionTest, ConnectStatus303) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6027 | ConnectStatusHelper(MockRead("HTTP/1.1 303 See Other\r\n")); |
| 6028 | } |
| 6029 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6030 | TEST_F(HttpNetworkTransactionTest, ConnectStatus304) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6031 | ConnectStatusHelper(MockRead("HTTP/1.1 304 Not Modified\r\n")); |
| 6032 | } |
| 6033 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6034 | TEST_F(HttpNetworkTransactionTest, ConnectStatus305) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6035 | ConnectStatusHelper(MockRead("HTTP/1.1 305 Use Proxy\r\n")); |
| 6036 | } |
| 6037 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6038 | TEST_F(HttpNetworkTransactionTest, ConnectStatus306) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6039 | ConnectStatusHelper(MockRead("HTTP/1.1 306\r\n")); |
| 6040 | } |
| 6041 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6042 | TEST_F(HttpNetworkTransactionTest, ConnectStatus307) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6043 | ConnectStatusHelper(MockRead("HTTP/1.1 307 Temporary Redirect\r\n")); |
| 6044 | } |
| 6045 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6046 | TEST_F(HttpNetworkTransactionTest, ConnectStatus308) { |
[email protected] | 0a17aab3 | 2014-04-24 03:32:37 | [diff] [blame] | 6047 | ConnectStatusHelper(MockRead("HTTP/1.1 308 Permanent Redirect\r\n")); |
| 6048 | } |
| 6049 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6050 | TEST_F(HttpNetworkTransactionTest, ConnectStatus400) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6051 | ConnectStatusHelper(MockRead("HTTP/1.1 400 Bad Request\r\n")); |
| 6052 | } |
| 6053 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6054 | TEST_F(HttpNetworkTransactionTest, ConnectStatus401) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6055 | ConnectStatusHelper(MockRead("HTTP/1.1 401 Unauthorized\r\n")); |
| 6056 | } |
| 6057 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6058 | TEST_F(HttpNetworkTransactionTest, ConnectStatus402) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6059 | ConnectStatusHelper(MockRead("HTTP/1.1 402 Payment Required\r\n")); |
| 6060 | } |
| 6061 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6062 | TEST_F(HttpNetworkTransactionTest, ConnectStatus403) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6063 | ConnectStatusHelper(MockRead("HTTP/1.1 403 Forbidden\r\n")); |
| 6064 | } |
| 6065 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6066 | TEST_F(HttpNetworkTransactionTest, ConnectStatus404) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6067 | ConnectStatusHelper(MockRead("HTTP/1.1 404 Not Found\r\n")); |
| 6068 | } |
| 6069 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6070 | TEST_F(HttpNetworkTransactionTest, ConnectStatus405) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6071 | ConnectStatusHelper(MockRead("HTTP/1.1 405 Method Not Allowed\r\n")); |
| 6072 | } |
| 6073 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6074 | TEST_F(HttpNetworkTransactionTest, ConnectStatus406) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6075 | ConnectStatusHelper(MockRead("HTTP/1.1 406 Not Acceptable\r\n")); |
| 6076 | } |
| 6077 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6078 | TEST_F(HttpNetworkTransactionTest, ConnectStatus407) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6079 | ConnectStatusHelperWithExpectedStatus( |
| 6080 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
[email protected] | a7ea883 | 2010-07-12 17:54:54 | [diff] [blame] | 6081 | ERR_PROXY_AUTH_UNSUPPORTED); |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6082 | } |
| 6083 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6084 | TEST_F(HttpNetworkTransactionTest, ConnectStatus408) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6085 | ConnectStatusHelper(MockRead("HTTP/1.1 408 Request Timeout\r\n")); |
| 6086 | } |
| 6087 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6088 | TEST_F(HttpNetworkTransactionTest, ConnectStatus409) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6089 | ConnectStatusHelper(MockRead("HTTP/1.1 409 Conflict\r\n")); |
| 6090 | } |
| 6091 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6092 | TEST_F(HttpNetworkTransactionTest, ConnectStatus410) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6093 | ConnectStatusHelper(MockRead("HTTP/1.1 410 Gone\r\n")); |
| 6094 | } |
| 6095 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6096 | TEST_F(HttpNetworkTransactionTest, ConnectStatus411) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6097 | ConnectStatusHelper(MockRead("HTTP/1.1 411 Length Required\r\n")); |
| 6098 | } |
| 6099 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6100 | TEST_F(HttpNetworkTransactionTest, ConnectStatus412) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6101 | ConnectStatusHelper(MockRead("HTTP/1.1 412 Precondition Failed\r\n")); |
| 6102 | } |
| 6103 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6104 | TEST_F(HttpNetworkTransactionTest, ConnectStatus413) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6105 | ConnectStatusHelper(MockRead("HTTP/1.1 413 Request Entity Too Large\r\n")); |
| 6106 | } |
| 6107 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6108 | TEST_F(HttpNetworkTransactionTest, ConnectStatus414) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6109 | ConnectStatusHelper(MockRead("HTTP/1.1 414 Request-URI Too Long\r\n")); |
| 6110 | } |
| 6111 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6112 | TEST_F(HttpNetworkTransactionTest, ConnectStatus415) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6113 | ConnectStatusHelper(MockRead("HTTP/1.1 415 Unsupported Media Type\r\n")); |
| 6114 | } |
| 6115 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6116 | TEST_F(HttpNetworkTransactionTest, ConnectStatus416) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6117 | ConnectStatusHelper( |
| 6118 | MockRead("HTTP/1.1 416 Requested Range Not Satisfiable\r\n")); |
| 6119 | } |
| 6120 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6121 | TEST_F(HttpNetworkTransactionTest, ConnectStatus417) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6122 | ConnectStatusHelper(MockRead("HTTP/1.1 417 Expectation Failed\r\n")); |
| 6123 | } |
| 6124 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6125 | TEST_F(HttpNetworkTransactionTest, ConnectStatus500) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6126 | ConnectStatusHelper(MockRead("HTTP/1.1 500 Internal Server Error\r\n")); |
| 6127 | } |
| 6128 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6129 | TEST_F(HttpNetworkTransactionTest, ConnectStatus501) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6130 | ConnectStatusHelper(MockRead("HTTP/1.1 501 Not Implemented\r\n")); |
| 6131 | } |
| 6132 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6133 | TEST_F(HttpNetworkTransactionTest, ConnectStatus502) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6134 | ConnectStatusHelper(MockRead("HTTP/1.1 502 Bad Gateway\r\n")); |
| 6135 | } |
| 6136 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6137 | TEST_F(HttpNetworkTransactionTest, ConnectStatus503) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6138 | ConnectStatusHelper(MockRead("HTTP/1.1 503 Service Unavailable\r\n")); |
| 6139 | } |
| 6140 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6141 | TEST_F(HttpNetworkTransactionTest, ConnectStatus504) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6142 | ConnectStatusHelper(MockRead("HTTP/1.1 504 Gateway Timeout\r\n")); |
| 6143 | } |
| 6144 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6145 | TEST_F(HttpNetworkTransactionTest, ConnectStatus505) { |
[email protected] | c744cf2 | 2009-02-27 07:28:08 | [diff] [blame] | 6146 | ConnectStatusHelper(MockRead("HTTP/1.1 505 HTTP Version Not Supported\r\n")); |
| 6147 | } |
| 6148 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6149 | // Test the flow when both the proxy server AND origin server require |
| 6150 | // authentication. Again, this uses basic auth for both since that is |
| 6151 | // the simplest to mock. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6152 | TEST_F(HttpNetworkTransactionTest, BasicAuthProxyThenServer) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6153 | HttpRequestInfo request; |
| 6154 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6155 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6156 | request.traffic_annotation = |
| 6157 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6158 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6159 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 6160 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 6161 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6162 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3fe8d2f8 | 2013-10-17 08:56:07 | [diff] [blame] | 6163 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6164 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6165 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6166 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6167 | MockWrite( |
| 6168 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6169 | "Host: www.example.org\r\n" |
| 6170 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 6171 | }; |
| 6172 | |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6173 | MockRead data_reads1[] = { |
| 6174 | MockRead("HTTP/1.0 407 Unauthorized\r\n"), |
| 6175 | // Give a couple authenticate options (only the middle one is actually |
| 6176 | // supported). |
[email protected] | 22927ad | 2009-09-21 19:56:19 | [diff] [blame] | 6177 | MockRead("Proxy-Authenticate: Basic invalid\r\n"), // Malformed. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6178 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6179 | MockRead("Proxy-Authenticate: UNSUPPORTED realm=\"FOO\"\r\n"), |
| 6180 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6181 | // Large content-length -- won't matter, as connection will be reset. |
| 6182 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6183 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6184 | }; |
| 6185 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6186 | // After calling trans.RestartWithAuth() the first time, this is the |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6187 | // request we should be issuing -- the final header line contains the |
| 6188 | // proxy's credentials. |
| 6189 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6190 | MockWrite( |
| 6191 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6192 | "Host: www.example.org\r\n" |
| 6193 | "Proxy-Connection: keep-alive\r\n" |
| 6194 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6195 | }; |
| 6196 | |
| 6197 | // Now the proxy server lets the request pass through to origin server. |
| 6198 | // The origin server responds with a 401. |
| 6199 | MockRead data_reads2[] = { |
| 6200 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 6201 | // Note: We are using the same realm-name as the proxy server. This is |
| 6202 | // completely valid, as realms are unique across hosts. |
| 6203 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 6204 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6205 | MockRead("Content-Length: 2000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6206 | MockRead(SYNCHRONOUS, ERR_FAILED), // Won't be reached. |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6207 | }; |
| 6208 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6209 | // After calling trans.RestartWithAuth() the second time, we should send |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6210 | // the credentials for both the proxy and origin server. |
| 6211 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6212 | MockWrite( |
| 6213 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 6214 | "Host: www.example.org\r\n" |
| 6215 | "Proxy-Connection: keep-alive\r\n" |
| 6216 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n" |
| 6217 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6218 | }; |
| 6219 | |
| 6220 | // Lastly we get the desired content. |
| 6221 | MockRead data_reads3[] = { |
| 6222 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 6223 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 6224 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 6225 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6226 | }; |
| 6227 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6228 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 6229 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 6230 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6231 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6232 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6233 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6234 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6235 | TestCompletionCallback callback1; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6236 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6237 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6238 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6239 | |
| 6240 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6241 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6242 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6243 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6244 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6245 | EXPECT_TRUE(CheckBasicProxyAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6246 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6247 | TestCompletionCallback callback2; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6248 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6249 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6250 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6251 | |
| 6252 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6253 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6254 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6255 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6256 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6257 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6258 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6259 | TestCompletionCallback callback3; |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6260 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6261 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 6262 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6263 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6264 | |
| 6265 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6266 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6267 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6268 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6269 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6270 | EXPECT_EQ(100, response->headers->GetContentLength()); |
[email protected] | 038e9a3 | 2008-10-08 22:40:16 | [diff] [blame] | 6271 | } |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6272 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6273 | // For the NTLM implementation using SSPI, we skip the NTLM tests since we |
| 6274 | // can't hook into its internals to cause it to generate predictable NTLM |
| 6275 | // authorization headers. |
| 6276 | #if defined(NTLM_PORTABLE) |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6277 | // The NTLM authentication unit tests are based on known test data from the |
| 6278 | // [MS-NLMP] Specification [1]. These tests are primarily of the authentication |
| 6279 | // flow rather than the implementation of the NTLM protocol. See net/ntlm |
| 6280 | // for the implementation and testing of the protocol. |
| 6281 | // |
| 6282 | // [1] https://msdn.microsoft.com/en-us/library/cc236621.aspx |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6283 | |
| 6284 | // Enter the correct password and authenticate successfully. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6285 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6286 | HttpRequestInfo request; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6287 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6288 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6289 | request.traffic_annotation = |
| 6290 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 6291 | |
| 6292 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 6293 | // to other auth schemes. |
| 6294 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6295 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6296 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6297 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6298 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6299 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6300 | // Generate the NTLM messages based on known test data. |
| 6301 | std::string negotiate_msg; |
| 6302 | std::string challenge_msg; |
| 6303 | std::string authenticate_msg; |
| 6304 | base::Base64Encode( |
| 6305 | base::StringPiece( |
| 6306 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6307 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6308 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6309 | base::Base64Encode( |
| 6310 | base::StringPiece( |
| 6311 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6312 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6313 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6314 | base::Base64Encode( |
| 6315 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6316 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6317 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6318 | arraysize( |
| 6319 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6320 | &authenticate_msg); |
| 6321 | |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6322 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6323 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6324 | "Host: server\r\n" |
| 6325 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6326 | }; |
| 6327 | |
| 6328 | MockRead data_reads1[] = { |
| 6329 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6330 | // Negotiate and NTLM are often requested together. However, we only want |
| 6331 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6332 | // the header that requests Negotiate for this test. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6333 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6334 | MockRead("Connection: close\r\n"), |
| 6335 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6336 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6337 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6338 | }; |
| 6339 | |
| 6340 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6341 | // After restarting with a null identity, this is the |
| 6342 | // request we should be issuing -- the final header line contains a Type |
| 6343 | // 1 message. |
| 6344 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6345 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6346 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6347 | "Authorization: NTLM "), |
| 6348 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6349 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6350 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6351 | // (using correct credentials). The second request continues on the |
| 6352 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6353 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6354 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6355 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6356 | "Authorization: NTLM "), |
| 6357 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6358 | }; |
| 6359 | |
| 6360 | MockRead data_reads2[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6361 | // The origin server responds with a Type 2 message. |
| 6362 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6363 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6364 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6365 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6366 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6367 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6368 | // Lastly we get the desired content. |
| 6369 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6370 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6371 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6372 | }; |
| 6373 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6374 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 6375 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6376 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6377 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6378 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6379 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6380 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6381 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6382 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6383 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6384 | TestCompletionCallback callback1; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6385 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6386 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6387 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6388 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6389 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6390 | |
| 6391 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6392 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6393 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6394 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6395 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6396 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6397 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6398 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6399 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6400 | TestCompletionCallback callback2; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6401 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6402 | rv = trans.RestartWithAuth( |
| 6403 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6404 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6405 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6406 | |
| 6407 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6408 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6409 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6410 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6411 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6412 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6413 | ASSERT_TRUE(response); |
| 6414 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6415 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6416 | TestCompletionCallback callback3; |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6417 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6418 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6419 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6420 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6421 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6422 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6423 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6424 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6425 | ASSERT_TRUE(response); |
| 6426 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6427 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6428 | |
| 6429 | std::string response_data; |
| 6430 | rv = ReadTransaction(&trans, &response_data); |
| 6431 | EXPECT_THAT(rv, IsOk()); |
| 6432 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6433 | |
| 6434 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6435 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6436 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6437 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
[email protected] | 3f91878 | 2009-02-28 01:29:24 | [diff] [blame] | 6438 | } |
| 6439 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6440 | // Enter a wrong password, and then the correct one. |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6441 | TEST_F(HttpNetworkTransactionTest, NTLMAuthV2WrongThenRightPassword) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6442 | HttpRequestInfo request; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6443 | request.method = "GET"; |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6444 | request.url = GURL("https://server/kids/login.aspx"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6445 | request.traffic_annotation = |
| 6446 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6447 | |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6448 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6449 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 6450 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 6451 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6452 | // Generate the NTLM messages based on known test data. |
| 6453 | std::string negotiate_msg; |
| 6454 | std::string challenge_msg; |
| 6455 | std::string authenticate_msg; |
| 6456 | base::Base64Encode( |
| 6457 | base::StringPiece( |
| 6458 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6459 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6460 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6461 | base::Base64Encode( |
| 6462 | base::StringPiece( |
| 6463 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6464 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6465 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6466 | base::Base64Encode( |
| 6467 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6468 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6469 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6470 | arraysize( |
| 6471 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6472 | &authenticate_msg); |
| 6473 | |
| 6474 | // The authenticate message when |kWrongPassword| is sent. |
| 6475 | std::string wrong_password_authenticate_msg( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6476 | "TlRMTVNTUAADAAAAGAAYAFgAAACKAIoAcAAAAAwADAD6AAAACAAIAAYBAAAQABAADgEAAAAA" |
| 6477 | "AABYAAAAA4IIAAAAAAAAAAAAAPknEYqtJQtusopDRSfYzAAAAAAAAAAAAAAAAAAAAAAAAAAA" |
| 6478 | "AAAAAOtVz38osnFdRRggUQHUJ3EBAQAAAAAAAIALyP0A1NIBqqqqqqqqqqoAAAAAAgAMAEQA" |
| 6479 | "bwBtAGEAaQBuAAEADABTAGUAcgB2AGUAcgAGAAQAAgAAAAoAEAAAAAAAAAAAAAAAAAAAAAAA" |
| 6480 | "CQAWAEgAVABUAFAALwBzAGUAcgB2AGUAcgAAAAAAAAAAAEQAbwBtAGEAaQBuAFUAcwBlAHIA" |
| 6481 | "QwBPAE0AUABVAFQARQBSAA=="); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6482 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6483 | // Sanity check that it's the same length as the correct authenticate message |
| 6484 | // and that it's different. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6485 | ASSERT_EQ(authenticate_msg.length(), |
| 6486 | wrong_password_authenticate_msg.length()); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6487 | ASSERT_NE(authenticate_msg, wrong_password_authenticate_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6488 | |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6489 | MockWrite data_writes1[] = { |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6490 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
| 6491 | "Host: server\r\n" |
| 6492 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6493 | }; |
| 6494 | |
| 6495 | MockRead data_reads1[] = { |
| 6496 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
[email protected] | aef0427 | 2010-06-28 18:03:04 | [diff] [blame] | 6497 | // Negotiate and NTLM are often requested together. However, we only want |
| 6498 | // to test NTLM. Since Negotiate is preferred over NTLM, we have to skip |
| 6499 | // the header that requests Negotiate for this test. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6500 | MockRead("WWW-Authenticate: NTLM\r\n"), |
| 6501 | MockRead("Connection: close\r\n"), |
| 6502 | MockRead("Content-Length: 42\r\n"), |
[email protected] | 076c8508 | 2009-04-10 23:21:36 | [diff] [blame] | 6503 | MockRead("Content-Type: text/html\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6504 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6505 | }; |
| 6506 | |
| 6507 | MockWrite data_writes2[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6508 | // After restarting with a null identity, this is the |
| 6509 | // request we should be issuing -- the final header line contains a Type |
| 6510 | // 1 message. |
| 6511 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6512 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6513 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6514 | "Authorization: NTLM "), |
| 6515 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6516 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6517 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6518 | // (using incorrect credentials). The second request continues on the |
| 6519 | // same connection. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6520 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6521 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6522 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6523 | "Authorization: NTLM "), |
| 6524 | MockWrite(wrong_password_authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6525 | }; |
| 6526 | |
| 6527 | MockRead data_reads2[] = { |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6528 | // The origin server responds with a Type 2 message. |
| 6529 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6530 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6531 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
| 6532 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6533 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6534 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6535 | // Wrong password. |
| 6536 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
| 6537 | MockRead("WWW-Authenticate: NTLM\r\n"), MockRead("Connection: close\r\n"), |
| 6538 | MockRead("Content-Length: 42\r\n"), |
| 6539 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6540 | // Missing content -- won't matter, as connection will be reset. |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6541 | }; |
| 6542 | |
| 6543 | MockWrite data_writes3[] = { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6544 | // After restarting with a null identity, this is the |
| 6545 | // request we should be issuing -- the final header line contains a Type |
| 6546 | // 1 message. |
| 6547 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6548 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6549 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6550 | "Authorization: NTLM "), |
| 6551 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6552 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6553 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6554 | // (the credentials for the origin server). The second request continues |
| 6555 | // on the same connection. |
| 6556 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6557 | "Host: server\r\n" |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6558 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6559 | "Authorization: NTLM "), |
| 6560 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6561 | }; |
| 6562 | |
| 6563 | MockRead data_reads3[] = { |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6564 | // The origin server responds with a Type 2 message. |
| 6565 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6566 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6567 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6568 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6569 | MockRead("You are not authorized to view this page\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6570 | |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6571 | // Lastly we get the desired content. |
| 6572 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6573 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
| 6574 | MockRead("Content-Length: 14\r\n\r\n"), MockRead("Please Login\r\n"), |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6575 | }; |
| 6576 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6577 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 6578 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 6579 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 6580 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6581 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6582 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6583 | |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6584 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6585 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6586 | SSLSocketDataProvider ssl2(ASYNC, OK); |
| 6587 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 6588 | SSLSocketDataProvider ssl3(ASYNC, OK); |
| 6589 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl3); |
| 6590 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6591 | TestCompletionCallback callback1; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6592 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6593 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 6594 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 6595 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6596 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6597 | |
| 6598 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6599 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6600 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6601 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6602 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6603 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6604 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6605 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6606 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6607 | TestCompletionCallback callback2; |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6608 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6609 | // Enter the wrong password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6610 | rv = trans.RestartWithAuth( |
| 6611 | AuthCredentials(ntlm::test::kDomainUserCombined, kWrongPassword), |
| 6612 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6613 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6614 | |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6615 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6616 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6617 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6618 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6619 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6620 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6621 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6622 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6623 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6624 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6625 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6626 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6627 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 6628 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6629 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6630 | TestCompletionCallback callback4; |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6631 | |
| 6632 | // Now enter the right password. |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6633 | rv = trans.RestartWithAuth( |
| 6634 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6635 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6636 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6637 | |
| 6638 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6639 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6640 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6641 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6642 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 6643 | TestCompletionCallback callback5; |
[email protected] | 10af5fe7 | 2011-01-31 16:17:25 | [diff] [blame] | 6644 | |
| 6645 | // One more roundtrip |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6646 | rv = trans.RestartWithAuth(AuthCredentials(), callback5.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6647 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6648 | |
| 6649 | rv = callback5.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 6650 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 6651 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 6652 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 6653 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6654 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6655 | |
| 6656 | std::string response_data; |
| 6657 | rv = ReadTransaction(&trans, &response_data); |
| 6658 | EXPECT_THAT(rv, IsOk()); |
| 6659 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6660 | |
| 6661 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6662 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
| 6663 | EXPECT_TRUE(data2.AllReadDataConsumed()); |
| 6664 | EXPECT_TRUE(data2.AllWriteDataConsumed()); |
| 6665 | EXPECT_TRUE(data3.AllReadDataConsumed()); |
| 6666 | EXPECT_TRUE(data3.AllWriteDataConsumed()); |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6667 | } |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6668 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 6669 | // Server requests NTLM authentication, which is not supported over HTTP/2. |
| 6670 | // Subsequent request with authorization header should be sent over HTTP/1.1. |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6671 | TEST_F(HttpNetworkTransactionTest, NTLMOverHttp2) { |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6672 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6673 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6674 | |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6675 | const char* kUrl = "https://server/kids/login.aspx"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6676 | |
| 6677 | HttpRequestInfo request; |
| 6678 | request.method = "GET"; |
| 6679 | request.url = GURL(kUrl); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6680 | request.traffic_annotation = |
| 6681 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6682 | |
| 6683 | // First request without credentials. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6684 | spdy::SpdyHeaderBlock request_headers0( |
| 6685 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
| 6686 | spdy::SpdySerializedFrame request0(spdy_util_.ConstructSpdyHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6687 | 1, std::move(request_headers0), LOWEST, true)); |
| 6688 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6689 | spdy::SpdyHeaderBlock response_headers0; |
| 6690 | response_headers0[spdy::kHttp2StatusHeader] = "401"; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6691 | response_headers0["www-authenticate"] = "NTLM"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6692 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyResponseHeaders( |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6693 | 1, std::move(response_headers0), true)); |
| 6694 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6695 | // Stream 1 is closed. |
| 6696 | spdy_util_.UpdateWithStreamDestruction(1); |
| 6697 | |
| 6698 | // Generate the NTLM messages based on known test data. |
| 6699 | std::string negotiate_msg; |
| 6700 | std::string challenge_msg; |
| 6701 | std::string authenticate_msg; |
| 6702 | base::Base64Encode( |
| 6703 | base::StringPiece( |
| 6704 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6705 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6706 | &negotiate_msg); |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6707 | base::Base64Encode( |
| 6708 | base::StringPiece( |
| 6709 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6710 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6711 | &challenge_msg); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6712 | base::Base64Encode( |
| 6713 | base::StringPiece( |
Zentaro Kavanagh | 6ccee51 | 2017-09-28 18:34:09 | [diff] [blame] | 6714 | reinterpret_cast<const char*>( |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6715 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6716 | arraysize( |
| 6717 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6718 | &authenticate_msg); |
| 6719 | |
| 6720 | // Retry with authorization header. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6721 | spdy::SpdyHeaderBlock request_headers1( |
| 6722 | spdy_util_.ConstructGetHeaderBlock(kUrl)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6723 | request_headers1["authorization"] = std::string("NTLM ") + negotiate_msg; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6724 | spdy::SpdySerializedFrame request1(spdy_util_.ConstructSpdyHeaders( |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6725 | 3, std::move(request_headers1), LOWEST, true)); |
| 6726 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 6727 | spdy::SpdySerializedFrame rst( |
| 6728 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_HTTP_1_1_REQUIRED)); |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6729 | |
Bence Béky | 3238f2e1 | 2017-09-22 22:44:49 | [diff] [blame] | 6730 | MockWrite writes0[] = {CreateMockWrite(request0, 0)}; |
| 6731 | MockRead reads0[] = {CreateMockRead(resp, 1), MockRead(ASYNC, 0, 2)}; |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6732 | |
| 6733 | // Retry yet again using HTTP/1.1. |
| 6734 | MockWrite writes1[] = { |
| 6735 | // After restarting with a null identity, this is the |
| 6736 | // request we should be issuing -- the final header line contains a Type |
| 6737 | // 1 message. |
| 6738 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6739 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6740 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6741 | "Authorization: NTLM "), |
| 6742 | MockWrite(negotiate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6743 | |
| 6744 | // After calling trans.RestartWithAuth(), we should send a Type 3 message |
| 6745 | // (the credentials for the origin server). The second request continues |
| 6746 | // on the same connection. |
| 6747 | MockWrite("GET /kids/login.aspx HTTP/1.1\r\n" |
Zentaro Kavanagh | 1890a3d | 2018-01-29 19:52:55 | [diff] [blame] | 6748 | "Host: server\r\n" |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6749 | "Connection: keep-alive\r\n" |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6750 | "Authorization: NTLM "), |
| 6751 | MockWrite(authenticate_msg.c_str()), MockWrite("\r\n\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6752 | }; |
| 6753 | |
| 6754 | MockRead reads1[] = { |
| 6755 | // The origin server responds with a Type 2 message. |
| 6756 | MockRead("HTTP/1.1 401 Access Denied\r\n"), |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6757 | MockRead("WWW-Authenticate: NTLM "), MockRead(challenge_msg.c_str()), |
| 6758 | MockRead("\r\n"), MockRead("Content-Length: 42\r\n"), |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6759 | MockRead("Content-Type: text/html\r\n\r\n"), |
| 6760 | MockRead("You are not authorized to view this page\r\n"), |
| 6761 | |
| 6762 | // Lastly we get the desired content. |
| 6763 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 6764 | MockRead("Content-Type: text/html; charset=utf-8\r\n"), |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6765 | 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] | 6766 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6767 | SequencedSocketData data0(reads0, writes0); |
| 6768 | StaticSocketDataProvider data1(reads1, writes1); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6769 | session_deps_.socket_factory->AddSocketDataProvider(&data0); |
| 6770 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 6771 | |
| 6772 | SSLSocketDataProvider ssl0(ASYNC, OK); |
| 6773 | ssl0.next_proto = kProtoHTTP2; |
| 6774 | SSLSocketDataProvider ssl1(ASYNC, OK); |
| 6775 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl0); |
| 6776 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 6777 | |
| 6778 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6779 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 6780 | |
| 6781 | TestCompletionCallback callback1; |
| 6782 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
| 6783 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6784 | |
| 6785 | rv = callback1.WaitForResult(); |
| 6786 | EXPECT_THAT(rv, IsOk()); |
| 6787 | |
| 6788 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 6789 | |
| 6790 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 6791 | ASSERT_TRUE(response); |
| 6792 | EXPECT_TRUE(CheckNTLMServerAuth(response->auth_challenge.get())); |
| 6793 | |
| 6794 | TestCompletionCallback callback2; |
| 6795 | |
Zentaro Kavanagh | 5b27a6e2 | 2017-09-25 23:00:37 | [diff] [blame] | 6796 | rv = trans.RestartWithAuth( |
| 6797 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6798 | callback2.callback()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6799 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6800 | |
| 6801 | rv = callback2.WaitForResult(); |
| 6802 | EXPECT_THAT(rv, IsOk()); |
| 6803 | |
| 6804 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 6805 | |
| 6806 | response = trans.GetResponseInfo(); |
| 6807 | ASSERT_TRUE(response); |
| 6808 | EXPECT_FALSE(response->auth_challenge); |
| 6809 | |
| 6810 | TestCompletionCallback callback3; |
| 6811 | |
| 6812 | rv = trans.RestartWithAuth(AuthCredentials(), callback3.callback()); |
| 6813 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 6814 | |
| 6815 | rv = callback3.WaitForResult(); |
| 6816 | EXPECT_THAT(rv, IsOk()); |
| 6817 | |
| 6818 | response = trans.GetResponseInfo(); |
| 6819 | ASSERT_TRUE(response); |
| 6820 | EXPECT_FALSE(response->auth_challenge); |
Bence Béky | 1e4ef19 | 2017-09-18 19:58:02 | [diff] [blame] | 6821 | EXPECT_EQ(14, response->headers->GetContentLength()); |
| 6822 | |
| 6823 | std::string response_data; |
| 6824 | rv = ReadTransaction(&trans, &response_data); |
| 6825 | EXPECT_THAT(rv, IsOk()); |
| 6826 | EXPECT_EQ("Please Login\r\n", response_data); |
| 6827 | |
| 6828 | EXPECT_TRUE(data0.AllReadDataConsumed()); |
| 6829 | EXPECT_TRUE(data0.AllWriteDataConsumed()); |
| 6830 | EXPECT_TRUE(data1.AllReadDataConsumed()); |
| 6831 | EXPECT_TRUE(data1.AllWriteDataConsumed()); |
Bence Béky | 83eb351 | 2017-09-05 12:56:09 | [diff] [blame] | 6832 | } |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 6833 | |
| 6834 | // Test that, if we have an NTLM proxy and the origin resets the connection, we |
| 6835 | // do no retry forever checking for TLS version interference. This is a |
| 6836 | // regression test for https://crbug.com/823387. |
| 6837 | TEST_F(HttpNetworkTransactionTest, NTLMProxyTLSHandshakeReset) { |
| 6838 | // The NTLM test data expects the proxy to be named 'server'. The origin is |
| 6839 | // https://origin/. |
| 6840 | session_deps_.proxy_resolution_service = |
| 6841 | ProxyResolutionService::CreateFixedFromPacResult( |
| 6842 | "PROXY server", TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6843 | |
| 6844 | SSLConfig config; |
| 6845 | config.version_max = SSL_PROTOCOL_VERSION_TLS1_3; |
| 6846 | session_deps_.ssl_config_service = |
Ryan Sleevi | b8449e0 | 2018-07-15 04:31:07 | [diff] [blame] | 6847 | std::make_unique<TestSSLConfigService>(config); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 6848 | |
| 6849 | HttpRequestInfo request; |
| 6850 | request.method = "GET"; |
| 6851 | request.url = GURL("https://origin/"); |
| 6852 | request.traffic_annotation = |
| 6853 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 6854 | |
| 6855 | // Ensure load is not disrupted by flags which suppress behaviour specific |
| 6856 | // to other auth schemes. |
| 6857 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
| 6858 | |
| 6859 | HttpAuthHandlerNTLM::ScopedProcSetter proc_setter( |
| 6860 | MockGetMSTime, MockGenerateRandom, MockGetHostName); |
| 6861 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 6862 | |
| 6863 | // Generate the NTLM messages based on known test data. |
| 6864 | std::string negotiate_msg; |
| 6865 | std::string challenge_msg; |
| 6866 | std::string authenticate_msg; |
| 6867 | base::Base64Encode( |
| 6868 | base::StringPiece( |
| 6869 | reinterpret_cast<const char*>(ntlm::test::kExpectedNegotiateMsg), |
| 6870 | arraysize(ntlm::test::kExpectedNegotiateMsg)), |
| 6871 | &negotiate_msg); |
| 6872 | base::Base64Encode( |
| 6873 | base::StringPiece( |
| 6874 | reinterpret_cast<const char*>(ntlm::test::kChallengeMsgFromSpecV2), |
| 6875 | arraysize(ntlm::test::kChallengeMsgFromSpecV2)), |
| 6876 | &challenge_msg); |
| 6877 | base::Base64Encode( |
| 6878 | base::StringPiece( |
| 6879 | reinterpret_cast<const char*>( |
| 6880 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2), |
| 6881 | arraysize( |
| 6882 | ntlm::test::kExpectedAuthenticateMsgEmptyChannelBindingsV2)), |
| 6883 | &authenticate_msg); |
| 6884 | |
| 6885 | MockWrite data_writes[] = { |
| 6886 | // The initial CONNECT request. |
| 6887 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 6888 | "Host: origin:443\r\n" |
| 6889 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 6890 | |
| 6891 | // After restarting with an identity. |
| 6892 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 6893 | "Host: origin:443\r\n" |
| 6894 | "Proxy-Connection: keep-alive\r\n" |
| 6895 | "Proxy-Authorization: NTLM "), |
| 6896 | MockWrite(negotiate_msg.c_str()), |
| 6897 | // End headers. |
| 6898 | MockWrite("\r\n\r\n"), |
| 6899 | |
| 6900 | // The second restart. |
| 6901 | MockWrite("CONNECT origin:443 HTTP/1.1\r\n" |
| 6902 | "Host: origin:443\r\n" |
| 6903 | "Proxy-Connection: keep-alive\r\n" |
| 6904 | "Proxy-Authorization: NTLM "), |
| 6905 | MockWrite(authenticate_msg.c_str()), |
| 6906 | // End headers. |
| 6907 | MockWrite("\r\n\r\n"), |
| 6908 | }; |
| 6909 | |
| 6910 | MockRead data_reads[] = { |
| 6911 | // The initial NTLM response. |
| 6912 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 6913 | "Content-Length: 0\r\n" |
| 6914 | "Proxy-Authenticate: NTLM\r\n\r\n"), |
| 6915 | |
| 6916 | // The NTLM challenge message. |
| 6917 | MockRead("HTTP/1.1 407 Access Denied\r\n" |
| 6918 | "Content-Length: 0\r\n" |
| 6919 | "Proxy-Authenticate: NTLM "), |
| 6920 | MockRead(challenge_msg.c_str()), |
| 6921 | // End headers. |
| 6922 | MockRead("\r\n\r\n"), |
| 6923 | |
| 6924 | // Finally the tunnel is established. |
| 6925 | MockRead("HTTP/1.1 200 Connected\r\n\r\n"), |
| 6926 | }; |
| 6927 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6928 | StaticSocketDataProvider data(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 6929 | SSLSocketDataProvider data_ssl(ASYNC, ERR_CONNECTION_RESET); |
Helen Li | 48f117e | 2018-05-29 20:38:40 | [diff] [blame] | 6930 | data_ssl.expected_ssl_version_max = SSL_PROTOCOL_VERSION_TLS1_3; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 6931 | StaticSocketDataProvider data2(data_reads, data_writes); |
David Benjamin | 5cb9113 | 2018-04-06 05:54:49 | [diff] [blame] | 6932 | SSLSocketDataProvider data_ssl2(ASYNC, ERR_CONNECTION_RESET); |
| 6933 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 6934 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl); |
| 6935 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 6936 | session_deps_.socket_factory->AddSSLSocketDataProvider(&data_ssl2); |
| 6937 | |
| 6938 | // Start the transaction. The proxy responds with an NTLM authentication |
| 6939 | // request. |
| 6940 | TestCompletionCallback callback; |
| 6941 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 6942 | int rv = callback.GetResult( |
| 6943 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
| 6944 | |
| 6945 | EXPECT_THAT(rv, IsOk()); |
| 6946 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
| 6947 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 6948 | ASSERT_TRUE(response); |
| 6949 | EXPECT_TRUE(CheckNTLMProxyAuth(response->auth_challenge.get())); |
| 6950 | |
| 6951 | // Configure credentials. The proxy responds with the challenge message. |
| 6952 | rv = callback.GetResult(trans.RestartWithAuth( |
| 6953 | AuthCredentials(ntlm::test::kDomainUserCombined, ntlm::test::kPassword), |
| 6954 | callback.callback())); |
| 6955 | EXPECT_THAT(rv, IsOk()); |
| 6956 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 6957 | response = trans.GetResponseInfo(); |
| 6958 | ASSERT_TRUE(response); |
| 6959 | EXPECT_FALSE(response->auth_challenge); |
| 6960 | |
| 6961 | // Restart once more. The tunnel will be established and the the SSL handshake |
| 6962 | // will reset. The TLS 1.3 version interference probe will then kick in and |
| 6963 | // restart the process. The proxy responds with another NTLM authentiation |
| 6964 | // request, but we don't need to provide credentials as the cached ones work/ |
| 6965 | rv = callback.GetResult( |
| 6966 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 6967 | EXPECT_THAT(rv, IsOk()); |
| 6968 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 6969 | response = trans.GetResponseInfo(); |
| 6970 | ASSERT_TRUE(response); |
| 6971 | EXPECT_FALSE(response->auth_challenge); |
| 6972 | |
| 6973 | // The proxy responds with the NTLM challenge message. |
| 6974 | rv = callback.GetResult( |
| 6975 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 6976 | EXPECT_THAT(rv, IsOk()); |
| 6977 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
| 6978 | response = trans.GetResponseInfo(); |
| 6979 | ASSERT_TRUE(response); |
| 6980 | EXPECT_FALSE(response->auth_challenge); |
| 6981 | |
| 6982 | // Send the NTLM authenticate message. The tunnel is established and the |
| 6983 | // handshake resets again. We should not retry again. |
| 6984 | rv = callback.GetResult( |
| 6985 | trans.RestartWithAuth(AuthCredentials(), callback.callback())); |
| 6986 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
| 6987 | } |
| 6988 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 6989 | #endif // NTLM_PORTABLE |
[email protected] | 385a467 | 2009-03-11 22:21:29 | [diff] [blame] | 6990 | |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6991 | // Test reading a server response which has only headers, and no body. |
| 6992 | // After some maximum number of bytes is consumed, the transaction should |
| 6993 | // fail with ERR_RESPONSE_HEADERS_TOO_BIG. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 6994 | TEST_F(HttpNetworkTransactionTest, LargeHeadersNoBody) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 6995 | HttpRequestInfo request; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 6996 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 6997 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 6998 | request.traffic_annotation = |
| 6999 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7000 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7001 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7002 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7003 | |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7004 | // Respond with 300 kb of headers (we should fail after 256 kb). |
[email protected] | 15a5ccf8 | 2008-10-23 19:57:43 | [diff] [blame] | 7005 | std::string large_headers_string; |
[email protected] | b75b7b2f | 2009-10-06 00:54:53 | [diff] [blame] | 7006 | FillLargeHeadersString(&large_headers_string, 300 * 1024); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7007 | |
| 7008 | MockRead data_reads[] = { |
| 7009 | MockRead("HTTP/1.0 200 OK\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7010 | MockRead(ASYNC, large_headers_string.data(), large_headers_string.size()), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7011 | MockRead("\r\nBODY"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7012 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7013 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7014 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7015 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7016 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7017 | TestCompletionCallback callback; |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7018 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7019 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7020 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7021 | |
| 7022 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7023 | EXPECT_THAT(rv, IsError(ERR_RESPONSE_HEADERS_TOO_BIG)); |
[email protected] | 4ddaf250 | 2008-10-23 18:26:19 | [diff] [blame] | 7024 | } |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7025 | |
| 7026 | // Make sure that we don't try to reuse a TCPClientSocket when failing to |
| 7027 | // establish tunnel. |
| 7028 | // http://code.google.com/p/chromium/issues/detail?id=3772 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7029 | TEST_F(HttpNetworkTransactionTest, DontRecycleTransportSocketForSSLTunnel) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7030 | HttpRequestInfo request; |
| 7031 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7032 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7033 | request.traffic_annotation = |
| 7034 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7035 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7036 | // Configure against proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 7037 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 7038 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | db8f44c | 2008-12-13 04:52:01 | [diff] [blame] | 7039 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7040 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7041 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7042 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7043 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7044 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7045 | // Since we have proxy, should try to establish tunnel. |
| 7046 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 7047 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 7048 | "Host: www.example.org:443\r\n" |
| 7049 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7050 | }; |
| 7051 | |
[email protected] | 77848d1 | 2008-11-14 00:00:22 | [diff] [blame] | 7052 | // The proxy responds to the connect with a 404, using a persistent |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7053 | // connection. Usually a proxy would return 501 (not implemented), |
| 7054 | // or 200 (tunnel established). |
| 7055 | MockRead data_reads1[] = { |
mmenke | d39192ee | 2015-12-09 00:57:23 | [diff] [blame] | 7056 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 7057 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7058 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7059 | }; |
| 7060 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7061 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7062 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7063 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7064 | TestCompletionCallback callback1; |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7065 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7066 | int rv = trans->Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7067 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7068 | |
| 7069 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7070 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7071 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7072 | // Empty the current queue. This is necessary because idle sockets are |
| 7073 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7074 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7075 | |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7076 | // We now check to make sure the TCPClientSocket was not added back to |
| 7077 | // the pool. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7078 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7079 | trans.reset(); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7080 | base::RunLoop().RunUntilIdle(); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7081 | // Make sure that the socket didn't get recycled after calling the destructor. |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7082 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | f4e426b | 2008-11-05 00:24:49 | [diff] [blame] | 7083 | } |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7084 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7085 | // Make sure that we recycle a socket after reading all of the response body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7086 | TEST_F(HttpNetworkTransactionTest, RecycleSocket) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7087 | HttpRequestInfo request; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7088 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7089 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7090 | request.traffic_annotation = |
| 7091 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7092 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7093 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7094 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7095 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7096 | |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7097 | MockRead data_reads[] = { |
| 7098 | // A part of the response body is received with the response headers. |
| 7099 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7100 | // The rest of the response body is received in two parts. |
| 7101 | MockRead("lo"), |
| 7102 | MockRead(" world"), |
| 7103 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7104 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7105 | }; |
| 7106 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7107 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7108 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7109 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7110 | TestCompletionCallback callback; |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7111 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7112 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7113 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7114 | |
| 7115 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7116 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7117 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7118 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7119 | ASSERT_TRUE(response); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7120 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7121 | EXPECT_TRUE(response->headers); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7122 | std::string status_line = response->headers->GetStatusLine(); |
| 7123 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7124 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7125 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7126 | |
| 7127 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7128 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7129 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7130 | EXPECT_EQ("hello world", response_data); |
| 7131 | |
| 7132 | // Empty the current queue. This is necessary because idle sockets are |
| 7133 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7134 | base::RunLoop().RunUntilIdle(); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7135 | |
| 7136 | // 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] | 7137 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 1b157c0 | 2009-04-21 01:55:40 | [diff] [blame] | 7138 | } |
| 7139 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7140 | // Make sure that we recycle a SSL socket after reading all of the response |
| 7141 | // body. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7142 | TEST_F(HttpNetworkTransactionTest, RecycleSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7143 | HttpRequestInfo request; |
| 7144 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7145 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7146 | request.traffic_annotation = |
| 7147 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7148 | |
| 7149 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7150 | MockWrite( |
| 7151 | "GET / HTTP/1.1\r\n" |
| 7152 | "Host: www.example.org\r\n" |
| 7153 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7154 | }; |
| 7155 | |
| 7156 | MockRead data_reads[] = { |
| 7157 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 7158 | MockRead("Content-Length: 11\r\n\r\n"), |
| 7159 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7160 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7161 | }; |
| 7162 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7163 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7164 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7165 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7166 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7167 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7168 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7169 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7170 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7171 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7172 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7173 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7174 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7175 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7176 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7177 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7178 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7179 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7180 | ASSERT_TRUE(response); |
| 7181 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7182 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7183 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7184 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7185 | |
| 7186 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7187 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7188 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7189 | EXPECT_EQ("hello world", response_data); |
| 7190 | |
| 7191 | // Empty the current queue. This is necessary because idle sockets are |
| 7192 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7193 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7194 | |
| 7195 | // 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] | 7196 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7197 | } |
| 7198 | |
| 7199 | // Grab a SSL socket, use it, and put it back into the pool. Then, reuse it |
| 7200 | // from the pool and make sure that we recover okay. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7201 | TEST_F(HttpNetworkTransactionTest, RecycleDeadSSLSocket) { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7202 | HttpRequestInfo request; |
| 7203 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7204 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7205 | request.traffic_annotation = |
| 7206 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7207 | |
| 7208 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7209 | MockWrite( |
| 7210 | "GET / HTTP/1.1\r\n" |
| 7211 | "Host: www.example.org\r\n" |
| 7212 | "Connection: keep-alive\r\n\r\n"), |
| 7213 | MockWrite( |
| 7214 | "GET / HTTP/1.1\r\n" |
| 7215 | "Host: www.example.org\r\n" |
| 7216 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7217 | }; |
| 7218 | |
| 7219 | MockRead data_reads[] = { |
mmenke | 911ee022 | 2015-12-04 03:58:42 | [diff] [blame] | 7220 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 7221 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7222 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7223 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 7224 | SSLSocketDataProvider ssl2(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7225 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7226 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7227 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7228 | StaticSocketDataProvider data(data_reads, data_writes); |
| 7229 | StaticSocketDataProvider data2(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7230 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7231 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7232 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7233 | TestCompletionCallback callback; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7234 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7235 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7236 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7237 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7238 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7239 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7240 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7241 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7242 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7243 | |
| 7244 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7245 | ASSERT_TRUE(response); |
| 7246 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7247 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7248 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7249 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7250 | |
| 7251 | std::string response_data; |
| 7252 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7253 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7254 | EXPECT_EQ("hello world", response_data); |
| 7255 | |
| 7256 | // Empty the current queue. This is necessary because idle sockets are |
| 7257 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7258 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7259 | |
| 7260 | // 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] | 7261 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7262 | |
| 7263 | // Now start the second transaction, which should reuse the previous socket. |
| 7264 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 7265 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7266 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7267 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7268 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7269 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7270 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7271 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7272 | |
| 7273 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7274 | ASSERT_TRUE(response); |
| 7275 | ASSERT_TRUE(response->headers); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7276 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7277 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7278 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7279 | |
| 7280 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7281 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7282 | EXPECT_EQ("hello world", response_data); |
| 7283 | |
| 7284 | // Empty the current queue. This is necessary because idle sockets are |
| 7285 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7286 | base::RunLoop().RunUntilIdle(); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7287 | |
| 7288 | // 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] | 7289 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 7290 | } |
| 7291 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7292 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 7293 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7294 | TEST_F(HttpNetworkTransactionTest, FlushSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7295 | HttpRequestInfo request; |
| 7296 | request.method = "GET"; |
| 7297 | request.url = GURL("http://www.example.org/"); |
| 7298 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7299 | request.traffic_annotation = |
| 7300 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7301 | |
| 7302 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7303 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7304 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7305 | |
| 7306 | MockRead data_reads[] = { |
| 7307 | // A part of the response body is received with the response headers. |
| 7308 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7309 | // The rest of the response body is received in two parts. |
| 7310 | MockRead("lo"), MockRead(" world"), |
| 7311 | MockRead("junk"), // Should not be read!! |
| 7312 | MockRead(SYNCHRONOUS, OK), |
| 7313 | }; |
| 7314 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7315 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7316 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7317 | |
| 7318 | TestCompletionCallback callback; |
| 7319 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7320 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7321 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7322 | |
| 7323 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7324 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7325 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7326 | ASSERT_TRUE(response); |
| 7327 | EXPECT_TRUE(response->headers); |
| 7328 | std::string status_line = response->headers->GetStatusLine(); |
| 7329 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7330 | |
| 7331 | // Make memory critical notification and ensure the transaction still has been |
| 7332 | // operating right. |
| 7333 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7334 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7335 | base::RunLoop().RunUntilIdle(); |
| 7336 | |
| 7337 | // Socket should not be flushed as long as it is not idle. |
| 7338 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7339 | |
| 7340 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7341 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7342 | EXPECT_THAT(rv, IsOk()); |
| 7343 | EXPECT_EQ("hello world", response_data); |
| 7344 | |
| 7345 | // Empty the current queue. This is necessary because idle sockets are |
| 7346 | // added to the connection pool asynchronously with a PostTask. |
| 7347 | base::RunLoop().RunUntilIdle(); |
| 7348 | |
| 7349 | // We now check to make sure the socket was added back to the pool. |
| 7350 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7351 | |
| 7352 | // Idle sockets should be flushed now. |
| 7353 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7354 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7355 | base::RunLoop().RunUntilIdle(); |
| 7356 | |
| 7357 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7358 | } |
| 7359 | |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 7360 | // Disable idle socket closing on memory pressure. |
| 7361 | // Grab a socket, use it, and put it back into the pool. Then, make |
| 7362 | // low memory notification and ensure the socket pool is NOT flushed. |
| 7363 | TEST_F(HttpNetworkTransactionTest, NoFlushSocketPoolOnLowMemoryNotifications) { |
| 7364 | HttpRequestInfo request; |
| 7365 | request.method = "GET"; |
| 7366 | request.url = GURL("http://www.example.org/"); |
| 7367 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7368 | request.traffic_annotation = |
| 7369 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 7370 | |
| 7371 | // Disable idle socket closing on memory pressure. |
| 7372 | session_deps_.disable_idle_sockets_close_on_memory_pressure = true; |
| 7373 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 7374 | |
| 7375 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 7376 | |
| 7377 | MockRead data_reads[] = { |
| 7378 | // A part of the response body is received with the response headers. |
| 7379 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\nhel"), |
| 7380 | // The rest of the response body is received in two parts. |
| 7381 | MockRead("lo"), MockRead(" world"), |
| 7382 | MockRead("junk"), // Should not be read!! |
| 7383 | MockRead(SYNCHRONOUS, OK), |
| 7384 | }; |
| 7385 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7386 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
yucliu | 48f235d | 2018-01-11 00:59:55 | [diff] [blame] | 7387 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7388 | |
| 7389 | TestCompletionCallback callback; |
| 7390 | |
| 7391 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 7392 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 7393 | |
| 7394 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7395 | |
| 7396 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 7397 | ASSERT_TRUE(response); |
| 7398 | EXPECT_TRUE(response->headers); |
| 7399 | std::string status_line = response->headers->GetStatusLine(); |
| 7400 | EXPECT_EQ("HTTP/1.1 200 OK", status_line); |
| 7401 | |
| 7402 | // Make memory critical notification and ensure the transaction still has been |
| 7403 | // operating right. |
| 7404 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7405 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7406 | base::RunLoop().RunUntilIdle(); |
| 7407 | |
| 7408 | // Socket should not be flushed as long as it is not idle. |
| 7409 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7410 | |
| 7411 | std::string response_data; |
| 7412 | rv = ReadTransaction(&trans, &response_data); |
| 7413 | EXPECT_THAT(rv, IsOk()); |
| 7414 | EXPECT_EQ("hello world", response_data); |
| 7415 | |
| 7416 | // Empty the current queue. This is necessary because idle sockets are |
| 7417 | // added to the connection pool asynchronously with a PostTask. |
| 7418 | base::RunLoop().RunUntilIdle(); |
| 7419 | |
| 7420 | // We now check to make sure the socket was added back to the pool. |
| 7421 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7422 | |
| 7423 | // Idle sockets should NOT be flushed on moderate memory pressure. |
| 7424 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7425 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_MODERATE); |
| 7426 | base::RunLoop().RunUntilIdle(); |
| 7427 | |
| 7428 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7429 | |
| 7430 | // Idle sockets should NOT be flushed on critical memory pressure. |
| 7431 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7432 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7433 | base::RunLoop().RunUntilIdle(); |
| 7434 | |
| 7435 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
| 7436 | } |
| 7437 | |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7438 | // Grab an SSL socket, use it, and put it back into the pool. Then, make |
| 7439 | // low memory notification and ensure the socket pool is flushed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7440 | TEST_F(HttpNetworkTransactionTest, FlushSSLSocketPoolOnLowMemoryNotifications) { |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7441 | HttpRequestInfo request; |
| 7442 | request.method = "GET"; |
| 7443 | request.url = GURL("https://www.example.org/"); |
| 7444 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7445 | request.traffic_annotation = |
| 7446 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7447 | |
| 7448 | MockWrite data_writes[] = { |
| 7449 | MockWrite("GET / HTTP/1.1\r\n" |
| 7450 | "Host: www.example.org\r\n" |
| 7451 | "Connection: keep-alive\r\n\r\n"), |
| 7452 | }; |
| 7453 | |
| 7454 | MockRead data_reads[] = { |
| 7455 | MockRead("HTTP/1.1 200 OK\r\n"), MockRead("Content-Length: 11\r\n\r\n"), |
| 7456 | MockRead("hello world"), MockRead(ASYNC, ERR_CONNECTION_CLOSED)}; |
| 7457 | |
| 7458 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 7459 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 7460 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7461 | StaticSocketDataProvider data(data_reads, data_writes); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7462 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 7463 | |
| 7464 | TestCompletionCallback callback; |
| 7465 | |
| 7466 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7467 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7468 | |
| 7469 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7470 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7471 | |
| 7472 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 7473 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7474 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7475 | ASSERT_TRUE(response); |
| 7476 | ASSERT_TRUE(response->headers); |
| 7477 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7478 | |
| 7479 | // Make memory critical notification and ensure the transaction still has been |
| 7480 | // operating right. |
| 7481 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7482 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7483 | base::RunLoop().RunUntilIdle(); |
| 7484 | |
| 7485 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7486 | |
| 7487 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7488 | rv = ReadTransaction(&trans, &response_data); |
maksim.sisov | 0adf859 | 2016-07-15 06:25:56 | [diff] [blame] | 7489 | EXPECT_THAT(rv, IsOk()); |
| 7490 | EXPECT_EQ("hello world", response_data); |
| 7491 | |
| 7492 | // Empty the current queue. This is necessary because idle sockets are |
| 7493 | // added to the connection pool asynchronously with a PostTask. |
| 7494 | base::RunLoop().RunUntilIdle(); |
| 7495 | |
| 7496 | // We now check to make sure the socket was added back to the pool. |
| 7497 | EXPECT_EQ(1, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7498 | |
| 7499 | // Make memory notification once again and ensure idle socket is closed. |
| 7500 | base::MemoryPressureListener::NotifyMemoryPressure( |
| 7501 | base::MemoryPressureListener::MEMORY_PRESSURE_LEVEL_CRITICAL); |
| 7502 | base::RunLoop().RunUntilIdle(); |
| 7503 | |
| 7504 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 7505 | } |
| 7506 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7507 | // Make sure that we recycle a socket after a zero-length response. |
| 7508 | // http://crbug.com/9880 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7509 | TEST_F(HttpNetworkTransactionTest, RecycleSocketAfterZeroContentLength) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7510 | HttpRequestInfo request; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7511 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7512 | request.url = GURL( |
| 7513 | "http://www.example.org/csi?v=3&s=web&action=&" |
| 7514 | "tran=undefined&ei=mAXcSeegAo-SMurloeUN&" |
| 7515 | "e=17259,18167,19592,19773,19981,20133,20173,20233&" |
| 7516 | "rt=prt.2642,ol.2649,xjs.2951"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7517 | request.traffic_annotation = |
| 7518 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7519 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7520 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7521 | |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7522 | MockRead data_reads[] = { |
| 7523 | MockRead("HTTP/1.1 204 No Content\r\n" |
| 7524 | "Content-Length: 0\r\n" |
| 7525 | "Content-Type: text/html\r\n\r\n"), |
| 7526 | MockRead("junk"), // Should not be read!! |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7527 | MockRead(SYNCHRONOUS, OK), |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7528 | }; |
| 7529 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7530 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7531 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7532 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 7533 | // Transaction must be created after the MockReads, so it's destroyed before |
| 7534 | // them. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7535 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 7536 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7537 | TestCompletionCallback callback; |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7538 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7539 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7540 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7541 | |
| 7542 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7543 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7544 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7545 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7546 | ASSERT_TRUE(response); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7547 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7548 | EXPECT_TRUE(response->headers); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7549 | std::string status_line = response->headers->GetStatusLine(); |
| 7550 | EXPECT_EQ("HTTP/1.1 204 No Content", status_line); |
| 7551 | |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 7552 | EXPECT_EQ(0, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7553 | |
| 7554 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7555 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7556 | EXPECT_THAT(rv, IsOk()); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7557 | EXPECT_EQ("", response_data); |
| 7558 | |
| 7559 | // Empty the current queue. This is necessary because idle sockets are |
| 7560 | // added to the connection pool asynchronously with a PostTask. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7561 | base::RunLoop().RunUntilIdle(); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7562 | |
| 7563 | // 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] | 7564 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | b4404c0 | 2009-04-10 16:38:52 | [diff] [blame] | 7565 | } |
| 7566 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7567 | TEST_F(HttpNetworkTransactionTest, ResendRequestOnWriteBodyError) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7568 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 7569 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 7570 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 7571 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7572 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7573 | HttpRequestInfo request[2]; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7574 | // Transaction 1: a GET request that succeeds. The socket is recycled |
| 7575 | // after use. |
| 7576 | request[0].method = "GET"; |
| 7577 | request[0].url = GURL("http://www.google.com/"); |
| 7578 | request[0].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7579 | request[0].traffic_annotation = |
| 7580 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7581 | // Transaction 2: a POST request. Reuses the socket kept alive from |
| 7582 | // transaction 1. The first attempts fails when writing the POST data. |
| 7583 | // This causes the transaction to retry with a new socket. The second |
| 7584 | // attempt succeeds. |
| 7585 | request[1].method = "POST"; |
| 7586 | request[1].url = GURL("http://www.google.com/login.cgi"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 7587 | request[1].upload_data_stream = &upload_data_stream; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7588 | request[1].load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7589 | request[1].traffic_annotation = |
| 7590 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7591 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7592 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7593 | |
| 7594 | // The first socket is used for transaction 1 and the first attempt of |
| 7595 | // transaction 2. |
| 7596 | |
| 7597 | // The response of transaction 1. |
| 7598 | MockRead data_reads1[] = { |
| 7599 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 11\r\n\r\n"), |
| 7600 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7601 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7602 | }; |
| 7603 | // The mock write results of transaction 1 and the first attempt of |
| 7604 | // transaction 2. |
| 7605 | MockWrite data_writes1[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7606 | MockWrite(SYNCHRONOUS, 64), // GET |
| 7607 | MockWrite(SYNCHRONOUS, 93), // POST |
| 7608 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_ABORTED), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7609 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7610 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7611 | |
| 7612 | // The second socket is used for the second attempt of transaction 2. |
| 7613 | |
| 7614 | // The response of transaction 2. |
| 7615 | MockRead data_reads2[] = { |
| 7616 | MockRead("HTTP/1.1 200 OK\r\nContent-Length: 7\r\n\r\n"), |
| 7617 | MockRead("welcome"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7618 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7619 | }; |
| 7620 | // The mock write results of the second attempt of transaction 2. |
| 7621 | MockWrite data_writes2[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7622 | MockWrite(SYNCHRONOUS, 93), // POST |
| 7623 | MockWrite(SYNCHRONOUS, 3), // POST data |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7624 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7625 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7626 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7627 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7628 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7629 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 7630 | const char* const kExpectedResponseData[] = { |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7631 | "hello world", "welcome" |
| 7632 | }; |
| 7633 | |
| 7634 | for (int i = 0; i < 2; ++i) { |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7635 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7636 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7637 | TestCompletionCallback callback; |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7638 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7639 | int rv = trans.Start(&request[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7640 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7641 | |
| 7642 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7643 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7644 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7645 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7646 | ASSERT_TRUE(response); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7647 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7648 | EXPECT_TRUE(response->headers); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7649 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 7650 | |
| 7651 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7652 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7653 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 372d34a | 2008-11-05 21:30:51 | [diff] [blame] | 7654 | EXPECT_EQ(kExpectedResponseData[i], response_data); |
| 7655 | } |
| 7656 | } |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7657 | |
| 7658 | // Test the request-challenge-retry sequence for basic auth when there is |
| 7659 | // 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] | 7660 | // it fails the identity from the URL is used to answer the challenge. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7661 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURL) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7662 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7663 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7664 | request.url = GURL("http://foo:b@[email protected]/"); |
[email protected] | 7b08ba6 | 2012-02-10 20:19:41 | [diff] [blame] | 7665 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7666 | request.traffic_annotation = |
| 7667 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7668 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7669 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7670 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7671 | |
[email protected] | a97cca4 | 2009-08-14 01:00:29 | [diff] [blame] | 7672 | // The password contains an escaped character -- for this test to pass it |
| 7673 | // will need to be unescaped by HttpNetworkTransaction. |
| 7674 | EXPECT_EQ("b%40r", request.url.password()); |
| 7675 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7676 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7677 | MockWrite( |
| 7678 | "GET / HTTP/1.1\r\n" |
| 7679 | "Host: www.example.org\r\n" |
| 7680 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7681 | }; |
| 7682 | |
| 7683 | MockRead data_reads1[] = { |
| 7684 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7685 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7686 | MockRead("Content-Length: 10\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7687 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7688 | }; |
| 7689 | |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7690 | // After the challenge above, the transaction will be restarted using the |
| 7691 | // identity from the url (foo, b@r) to answer the challenge. |
| 7692 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7693 | MockWrite( |
| 7694 | "GET / HTTP/1.1\r\n" |
| 7695 | "Host: www.example.org\r\n" |
| 7696 | "Connection: keep-alive\r\n" |
| 7697 | "Authorization: Basic Zm9vOmJAcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7698 | }; |
| 7699 | |
| 7700 | MockRead data_reads2[] = { |
| 7701 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7702 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7703 | MockRead(SYNCHRONOUS, OK), |
| 7704 | }; |
| 7705 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7706 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7707 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7708 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7709 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7710 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7711 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7712 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7713 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7714 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7715 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7716 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7717 | |
| 7718 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7719 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7720 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7721 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7722 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7723 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 7724 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7725 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7726 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7727 | |
| 7728 | // There is no challenge info, since the identity in URL worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7729 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7730 | |
| 7731 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7732 | |
| 7733 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7734 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7735 | } |
| 7736 | |
| 7737 | // Test the request-challenge-retry sequence for basic auth when there is an |
| 7738 | // incorrect identity in the URL. The identity from the URL should be used only |
| 7739 | // once. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7740 | TEST_F(HttpNetworkTransactionTest, WrongAuthIdentityInURL) { |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7741 | HttpRequestInfo request; |
| 7742 | request.method = "GET"; |
| 7743 | // Note: the URL has a username:password in it. The password "baz" is |
| 7744 | // wrong (should be "bar"). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7745 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7746 | |
| 7747 | request.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7748 | request.traffic_annotation = |
| 7749 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7750 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7751 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7752 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7753 | |
| 7754 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7755 | MockWrite( |
| 7756 | "GET / HTTP/1.1\r\n" |
| 7757 | "Host: www.example.org\r\n" |
| 7758 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7759 | }; |
| 7760 | |
| 7761 | MockRead data_reads1[] = { |
| 7762 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7763 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7764 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7765 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7766 | }; |
| 7767 | |
| 7768 | // After the challenge above, the transaction will be restarted using the |
| 7769 | // identity from the url (foo, baz) to answer the challenge. |
| 7770 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7771 | MockWrite( |
| 7772 | "GET / HTTP/1.1\r\n" |
| 7773 | "Host: www.example.org\r\n" |
| 7774 | "Connection: keep-alive\r\n" |
| 7775 | "Authorization: Basic Zm9vOmJheg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7776 | }; |
| 7777 | |
| 7778 | MockRead data_reads2[] = { |
| 7779 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7780 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7781 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7782 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7783 | }; |
| 7784 | |
| 7785 | // After the challenge above, the transaction will be restarted using the |
| 7786 | // identity supplied by the user (foo, bar) to answer the challenge. |
| 7787 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7788 | MockWrite( |
| 7789 | "GET / HTTP/1.1\r\n" |
| 7790 | "Host: www.example.org\r\n" |
| 7791 | "Connection: keep-alive\r\n" |
| 7792 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7793 | }; |
| 7794 | |
| 7795 | MockRead data_reads3[] = { |
| 7796 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7797 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7798 | MockRead(SYNCHRONOUS, OK), |
| 7799 | }; |
| 7800 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7801 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7802 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 7803 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7804 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7805 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 7806 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7807 | |
| 7808 | TestCompletionCallback callback1; |
| 7809 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7810 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7811 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7812 | |
| 7813 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7814 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7815 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7816 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7817 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7818 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7819 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7820 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7821 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7822 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7823 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7824 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7825 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7826 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7827 | |
| 7828 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7829 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7830 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7831 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7832 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7833 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7834 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7835 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7836 | ASSERT_TRUE(response); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7837 | |
| 7838 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7839 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2262e3a | 2012-05-22 16:08:16 | [diff] [blame] | 7840 | |
| 7841 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7842 | |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7843 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7844 | base::RunLoop().RunUntilIdle(); |
[email protected] | ea9dc9a | 2009-09-05 00:43:32 | [diff] [blame] | 7845 | } |
| 7846 | |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7847 | |
| 7848 | // Test the request-challenge-retry sequence for basic auth when there is a |
| 7849 | // correct identity in the URL, but its use is being suppressed. The identity |
| 7850 | // from the URL should never be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7851 | TEST_F(HttpNetworkTransactionTest, AuthIdentityInURLSuppressed) { |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7852 | HttpRequestInfo request; |
| 7853 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7854 | request.url = GURL("http://foo:[email protected]/"); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7855 | request.load_flags = LOAD_DO_NOT_USE_EMBEDDED_IDENTITY; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7856 | request.traffic_annotation = |
| 7857 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7858 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7859 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7860 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7861 | |
| 7862 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7863 | MockWrite( |
| 7864 | "GET / HTTP/1.1\r\n" |
| 7865 | "Host: www.example.org\r\n" |
| 7866 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7867 | }; |
| 7868 | |
| 7869 | MockRead data_reads1[] = { |
| 7870 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7871 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7872 | MockRead("Content-Length: 10\r\n\r\n"), |
| 7873 | MockRead(SYNCHRONOUS, ERR_FAILED), |
| 7874 | }; |
| 7875 | |
| 7876 | // After the challenge above, the transaction will be restarted using the |
| 7877 | // identity supplied by the user, not the one in the URL, to answer the |
| 7878 | // challenge. |
| 7879 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7880 | MockWrite( |
| 7881 | "GET / HTTP/1.1\r\n" |
| 7882 | "Host: www.example.org\r\n" |
| 7883 | "Connection: keep-alive\r\n" |
| 7884 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7885 | }; |
| 7886 | |
| 7887 | MockRead data_reads3[] = { |
| 7888 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7889 | MockRead("Content-Length: 100\r\n\r\n"), |
| 7890 | MockRead(SYNCHRONOUS, OK), |
| 7891 | }; |
| 7892 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7893 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7894 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7895 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7896 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 7897 | |
| 7898 | TestCompletionCallback callback1; |
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] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7901 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7902 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7903 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7904 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7905 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7906 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7907 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
| 7908 | |
| 7909 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7910 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7911 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7912 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7913 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7914 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7915 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7916 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7917 | ASSERT_TRUE(response); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7918 | |
| 7919 | // There is no challenge info, since the identity worked. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7920 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7921 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 7922 | |
| 7923 | // Empty the current queue. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 7924 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2217aa2 | 2013-10-11 03:03:54 | [diff] [blame] | 7925 | } |
| 7926 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7927 | // Test that previously tried username/passwords for a realm get re-used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 7928 | TEST_F(HttpNetworkTransactionTest, BasicAuthCacheAndPreauth) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 7929 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7930 | |
| 7931 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 7932 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 7933 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7934 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7935 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 7936 | request.traffic_annotation = |
| 7937 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7938 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7939 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 7940 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7941 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7942 | MockWrite( |
| 7943 | "GET /x/y/z HTTP/1.1\r\n" |
| 7944 | "Host: www.example.org\r\n" |
| 7945 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7946 | }; |
| 7947 | |
| 7948 | MockRead data_reads1[] = { |
| 7949 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 7950 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 7951 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7952 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7953 | }; |
| 7954 | |
| 7955 | // Resend with authorization (username=foo, password=bar) |
| 7956 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 7957 | MockWrite( |
| 7958 | "GET /x/y/z HTTP/1.1\r\n" |
| 7959 | "Host: www.example.org\r\n" |
| 7960 | "Connection: keep-alive\r\n" |
| 7961 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7962 | }; |
| 7963 | |
| 7964 | // Sever accepts the authorization. |
| 7965 | MockRead data_reads2[] = { |
| 7966 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 7967 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 7968 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7969 | }; |
| 7970 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 7971 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 7972 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 7973 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 7974 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7975 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7976 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7977 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 7978 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7979 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7980 | |
| 7981 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7982 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7983 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7984 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7985 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 7986 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7987 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 7988 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7989 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7990 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 7991 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7992 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7993 | |
| 7994 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 7995 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 7996 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 7997 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 7998 | ASSERT_TRUE(response); |
| 7999 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8000 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8001 | } |
| 8002 | |
| 8003 | // ------------------------------------------------------------------------ |
| 8004 | |
| 8005 | // Transaction 2: authenticate (foo2, bar2) on MyRealm2 |
| 8006 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8007 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8008 | request.method = "GET"; |
| 8009 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8010 | // protection space as MyRealm1. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8011 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8012 | request.traffic_annotation = |
| 8013 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8014 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8015 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8016 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8017 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8018 | MockWrite( |
| 8019 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8020 | "Host: www.example.org\r\n" |
| 8021 | "Connection: keep-alive\r\n" |
| 8022 | // Send preemptive authorization for MyRealm1 |
| 8023 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8024 | }; |
| 8025 | |
| 8026 | // The server didn't like the preemptive authorization, and |
| 8027 | // challenges us for a different realm (MyRealm2). |
| 8028 | MockRead data_reads1[] = { |
| 8029 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8030 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm2\"\r\n"), |
| 8031 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8032 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8033 | }; |
| 8034 | |
| 8035 | // Resend with authorization for MyRealm2 (username=foo2, password=bar2) |
| 8036 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8037 | MockWrite( |
| 8038 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8039 | "Host: www.example.org\r\n" |
| 8040 | "Connection: keep-alive\r\n" |
| 8041 | "Authorization: Basic Zm9vMjpiYXIy\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8042 | }; |
| 8043 | |
| 8044 | // Sever accepts the authorization. |
| 8045 | MockRead data_reads2[] = { |
| 8046 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8047 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8048 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8049 | }; |
| 8050 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8051 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8052 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8053 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8054 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8055 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8056 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8057 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8058 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8059 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8060 | |
| 8061 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8062 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8063 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8064 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8065 | ASSERT_TRUE(response); |
| 8066 | ASSERT_TRUE(response->auth_challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8067 | EXPECT_FALSE(response->auth_challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 8068 | EXPECT_EQ("http://www.example.org", |
| 8069 | response->auth_challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8070 | EXPECT_EQ("MyRealm2", response->auth_challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 8071 | EXPECT_EQ(kBasicAuthScheme, response->auth_challenge->scheme); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8072 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8073 | TestCompletionCallback callback2; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8074 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8075 | rv = trans.RestartWithAuth(AuthCredentials(kFoo2, kBar2), |
| 8076 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8077 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8078 | |
| 8079 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8080 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8081 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8082 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8083 | ASSERT_TRUE(response); |
| 8084 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8085 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8086 | } |
| 8087 | |
| 8088 | // ------------------------------------------------------------------------ |
| 8089 | |
| 8090 | // Transaction 3: Resend a request in MyRealm's protection space -- |
| 8091 | // succeed with preemptive authorization. |
| 8092 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8093 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8094 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8095 | request.url = GURL("http://www.example.org/x/y/z2"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8096 | request.traffic_annotation = |
| 8097 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8098 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8099 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8100 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8101 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8102 | MockWrite( |
| 8103 | "GET /x/y/z2 HTTP/1.1\r\n" |
| 8104 | "Host: www.example.org\r\n" |
| 8105 | "Connection: keep-alive\r\n" |
| 8106 | // The authorization for MyRealm1 gets sent preemptively |
| 8107 | // (since the url is in the same protection space) |
| 8108 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8109 | }; |
| 8110 | |
| 8111 | // Sever accepts the preemptive authorization |
| 8112 | MockRead data_reads1[] = { |
| 8113 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8114 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8115 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8116 | }; |
| 8117 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8118 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8119 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8120 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8121 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8122 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8123 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8124 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8125 | |
| 8126 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8127 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8128 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8129 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8130 | ASSERT_TRUE(response); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8131 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8132 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8133 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8134 | } |
| 8135 | |
| 8136 | // ------------------------------------------------------------------------ |
| 8137 | |
| 8138 | // Transaction 4: request another URL in MyRealm (however the |
| 8139 | // url is not known to belong to the protection space, so no pre-auth). |
| 8140 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8141 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8142 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8143 | request.url = GURL("http://www.example.org/x/1"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8144 | request.traffic_annotation = |
| 8145 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8146 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8147 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8148 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8149 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8150 | MockWrite( |
| 8151 | "GET /x/1 HTTP/1.1\r\n" |
| 8152 | "Host: www.example.org\r\n" |
| 8153 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8154 | }; |
| 8155 | |
| 8156 | MockRead data_reads1[] = { |
| 8157 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8158 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8159 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8160 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8161 | }; |
| 8162 | |
| 8163 | // Resend with authorization from MyRealm's cache. |
| 8164 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8165 | MockWrite( |
| 8166 | "GET /x/1 HTTP/1.1\r\n" |
| 8167 | "Host: www.example.org\r\n" |
| 8168 | "Connection: keep-alive\r\n" |
| 8169 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8170 | }; |
| 8171 | |
| 8172 | // Sever accepts the authorization. |
| 8173 | MockRead data_reads2[] = { |
| 8174 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8175 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8176 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8177 | }; |
| 8178 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8179 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8180 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8181 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8182 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8183 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8184 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8185 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8186 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8187 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8188 | |
| 8189 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8190 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8191 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8192 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8193 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8194 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8195 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8196 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8197 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8198 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8199 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8200 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8201 | ASSERT_TRUE(response); |
| 8202 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8203 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8204 | } |
| 8205 | |
| 8206 | // ------------------------------------------------------------------------ |
| 8207 | |
| 8208 | // Transaction 5: request a URL in MyRealm, but the server rejects the |
| 8209 | // cached identity. Should invalidate and re-prompt. |
| 8210 | { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 8211 | HttpRequestInfo request; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8212 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8213 | request.url = GURL("http://www.example.org/p/q/t"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8214 | request.traffic_annotation = |
| 8215 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8216 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8217 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8218 | |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8219 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8220 | MockWrite( |
| 8221 | "GET /p/q/t HTTP/1.1\r\n" |
| 8222 | "Host: www.example.org\r\n" |
| 8223 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8224 | }; |
| 8225 | |
| 8226 | MockRead data_reads1[] = { |
| 8227 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8228 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8229 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8230 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8231 | }; |
| 8232 | |
| 8233 | // Resend with authorization from cache for MyRealm. |
| 8234 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8235 | MockWrite( |
| 8236 | "GET /p/q/t HTTP/1.1\r\n" |
| 8237 | "Host: www.example.org\r\n" |
| 8238 | "Connection: keep-alive\r\n" |
| 8239 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8240 | }; |
| 8241 | |
| 8242 | // Sever rejects the authorization. |
| 8243 | MockRead data_reads2[] = { |
| 8244 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8245 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 8246 | MockRead("Content-Length: 10000\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8247 | MockRead(SYNCHRONOUS, ERR_FAILED), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8248 | }; |
| 8249 | |
| 8250 | // At this point we should prompt for new credentials for MyRealm. |
| 8251 | // Restart with username=foo3, password=foo4. |
| 8252 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8253 | MockWrite( |
| 8254 | "GET /p/q/t HTTP/1.1\r\n" |
| 8255 | "Host: www.example.org\r\n" |
| 8256 | "Connection: keep-alive\r\n" |
| 8257 | "Authorization: Basic Zm9vMzpiYXIz\r\n\r\n"), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8258 | }; |
| 8259 | |
| 8260 | // Sever accepts the authorization. |
| 8261 | MockRead data_reads3[] = { |
| 8262 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8263 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8264 | MockRead(SYNCHRONOUS, OK), |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8265 | }; |
| 8266 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8267 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8268 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 8269 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8270 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8271 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 8272 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8273 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8274 | TestCompletionCallback callback1; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8275 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8276 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8277 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8278 | |
| 8279 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8280 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8281 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8282 | EXPECT_TRUE(trans.IsReadyToRestartForAuth()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8283 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8284 | rv = trans.RestartWithAuth(AuthCredentials(), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8285 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8286 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8287 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8288 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8289 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8290 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8291 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8292 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8293 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8294 | TestCompletionCallback callback3; |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8295 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8296 | rv = trans.RestartWithAuth(AuthCredentials(kFoo3, kBar3), |
| 8297 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8298 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8299 | |
[email protected] | 0757e770 | 2009-03-27 04:00:22 | [diff] [blame] | 8300 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8301 | EXPECT_THAT(rv, IsOk()); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8302 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8303 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8304 | ASSERT_TRUE(response); |
| 8305 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | f9ee6b5 | 2008-11-08 06:46:23 | [diff] [blame] | 8306 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8307 | } |
| 8308 | } |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8309 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8310 | // Tests that nonce count increments when multiple auth attempts |
| 8311 | // are started with the same nonce. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8312 | TEST_F(HttpNetworkTransactionTest, DigestPreAuthNonceCount) { |
[email protected] | 54fea256 | 2010-11-17 14:40:44 | [diff] [blame] | 8313 | HttpAuthHandlerDigest::Factory* digest_factory = |
| 8314 | new HttpAuthHandlerDigest::Factory(); |
| 8315 | HttpAuthHandlerDigest::FixedNonceGenerator* nonce_generator = |
| 8316 | new HttpAuthHandlerDigest::FixedNonceGenerator("0123456789abcdef"); |
| 8317 | digest_factory->set_nonce_generator(nonce_generator); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8318 | session_deps_.http_auth_handler_factory.reset(digest_factory); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8319 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8320 | |
| 8321 | // Transaction 1: authenticate (foo, bar) on MyRealm1 |
| 8322 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8323 | HttpRequestInfo request; |
| 8324 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8325 | request.url = GURL("http://www.example.org/x/y/z"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8326 | request.traffic_annotation = |
| 8327 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8328 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8329 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8330 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8331 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8332 | MockWrite( |
| 8333 | "GET /x/y/z HTTP/1.1\r\n" |
| 8334 | "Host: www.example.org\r\n" |
| 8335 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8336 | }; |
| 8337 | |
| 8338 | MockRead data_reads1[] = { |
| 8339 | MockRead("HTTP/1.0 401 Unauthorized\r\n"), |
| 8340 | MockRead("WWW-Authenticate: Digest realm=\"digestive\", nonce=\"OU812\", " |
| 8341 | "algorithm=MD5, qop=\"auth\"\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8342 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8343 | }; |
| 8344 | |
| 8345 | // Resend with authorization (username=foo, password=bar) |
| 8346 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8347 | MockWrite( |
| 8348 | "GET /x/y/z HTTP/1.1\r\n" |
| 8349 | "Host: www.example.org\r\n" |
| 8350 | "Connection: keep-alive\r\n" |
| 8351 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 8352 | "nonce=\"OU812\", uri=\"/x/y/z\", algorithm=MD5, " |
| 8353 | "response=\"03ffbcd30add722589c1de345d7a927f\", qop=auth, " |
| 8354 | "nc=00000001, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8355 | }; |
| 8356 | |
| 8357 | // Sever accepts the authorization. |
| 8358 | MockRead data_reads2[] = { |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 8359 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8360 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8361 | }; |
| 8362 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8363 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 8364 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8365 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 8366 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8367 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8368 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8369 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8370 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8371 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8372 | |
| 8373 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8374 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8375 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8376 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8377 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 8378 | EXPECT_TRUE(CheckDigestServerAuth(response->auth_challenge.get())); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8379 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8380 | TestCompletionCallback callback2; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8381 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8382 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 8383 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8384 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8385 | |
| 8386 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8387 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8388 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8389 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8390 | ASSERT_TRUE(response); |
| 8391 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8392 | } |
| 8393 | |
| 8394 | // ------------------------------------------------------------------------ |
| 8395 | |
| 8396 | // Transaction 2: Request another resource in digestive's protection space. |
| 8397 | // This will preemptively add an Authorization header which should have an |
| 8398 | // "nc" value of 2 (as compared to 1 in the first use. |
| 8399 | { |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8400 | HttpRequestInfo request; |
| 8401 | request.method = "GET"; |
| 8402 | // Note that Transaction 1 was at /x/y/z, so this is in the same |
| 8403 | // protection space as digest. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8404 | request.url = GURL("http://www.example.org/x/y/a/b"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8405 | request.traffic_annotation = |
| 8406 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8407 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8408 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8409 | |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8410 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8411 | MockWrite( |
| 8412 | "GET /x/y/a/b HTTP/1.1\r\n" |
| 8413 | "Host: www.example.org\r\n" |
| 8414 | "Connection: keep-alive\r\n" |
| 8415 | "Authorization: Digest username=\"foo\", realm=\"digestive\", " |
| 8416 | "nonce=\"OU812\", uri=\"/x/y/a/b\", algorithm=MD5, " |
| 8417 | "response=\"d6f9a2c07d1c5df7b89379dca1269b35\", qop=auth, " |
| 8418 | "nc=00000002, cnonce=\"0123456789abcdef\"\r\n\r\n"), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8419 | }; |
| 8420 | |
| 8421 | // Sever accepts the authorization. |
| 8422 | MockRead data_reads1[] = { |
| 8423 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8424 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8425 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8426 | }; |
| 8427 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8428 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8429 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8430 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8431 | TestCompletionCallback callback1; |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8432 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8433 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8434 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8435 | |
| 8436 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8437 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8438 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8439 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8440 | ASSERT_TRUE(response); |
| 8441 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 3c32c5f | 2010-05-18 15:18:12 | [diff] [blame] | 8442 | } |
| 8443 | } |
| 8444 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8445 | // Test the ResetStateForRestart() private method. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8446 | TEST_F(HttpNetworkTransactionTest, ResetStateForRestart) { |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8447 | // Create a transaction (the dependencies aren't important). |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8448 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8449 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8450 | |
| 8451 | // Setup some state (which we expect ResetStateForRestart() will clear). |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 8452 | trans.read_buf_ = base::MakeRefCounted<IOBuffer>(15); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8453 | trans.read_buf_len_ = 15; |
| 8454 | trans.request_headers_.SetHeader("Authorization", "NTLM"); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8455 | |
| 8456 | // Setup state in response_ |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8457 | HttpResponseInfo* response = &trans.response_; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8458 | response->auth_challenge = new AuthChallengeInfo(); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 8459 | response->ssl_info.cert_status = static_cast<CertStatus>(-1); // Nonsensical. |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8460 | response->response_time = base::Time::Now(); |
| 8461 | response->was_cached = true; // (Wouldn't ever actually be true...) |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8462 | |
| 8463 | { // Setup state for response_.vary_data |
| 8464 | HttpRequestInfo request; |
| 8465 | std::string temp("HTTP/1.1 200 OK\nVary: foo, bar\n\n"); |
| 8466 | std::replace(temp.begin(), temp.end(), '\n', '\0'); |
[email protected] | ad8e04a | 2010-11-01 04:16:27 | [diff] [blame] | 8467 | scoped_refptr<HttpResponseHeaders> headers(new HttpResponseHeaders(temp)); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 8468 | request.extra_headers.SetHeader("Foo", "1"); |
| 8469 | request.extra_headers.SetHeader("bar", "23"); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 8470 | EXPECT_TRUE(response->vary_data.Init(request, *headers.get())); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8471 | } |
| 8472 | |
| 8473 | // Cause the above state to be reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8474 | trans.ResetStateForRestart(); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8475 | |
| 8476 | // Verify that the state that needed to be reset, has been reset. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8477 | EXPECT_FALSE(trans.read_buf_); |
| 8478 | EXPECT_EQ(0, trans.read_buf_len_); |
| 8479 | EXPECT_TRUE(trans.request_headers_.IsEmpty()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8480 | EXPECT_FALSE(response->auth_challenge); |
| 8481 | EXPECT_FALSE(response->headers); |
[email protected] | 34f4094 | 2010-10-04 00:34:04 | [diff] [blame] | 8482 | EXPECT_FALSE(response->was_cached); |
[email protected] | 70d6650 | 2011-09-23 00:55:08 | [diff] [blame] | 8483 | EXPECT_EQ(0U, response->ssl_info.cert_status); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 8484 | EXPECT_FALSE(response->vary_data.is_valid()); |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 8485 | } |
| 8486 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8487 | // Test HTTPS connections to a site with a bad certificate |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8488 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificate) { |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8489 | HttpRequestInfo request; |
| 8490 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8491 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8492 | request.traffic_annotation = |
| 8493 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8494 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8495 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8496 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 8497 | |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8498 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8499 | MockWrite( |
| 8500 | "GET / HTTP/1.1\r\n" |
| 8501 | "Host: www.example.org\r\n" |
| 8502 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8503 | }; |
| 8504 | |
| 8505 | MockRead data_reads[] = { |
| 8506 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8507 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8508 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8509 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8510 | }; |
| 8511 | |
[email protected] | 5ecc992a4 | 2009-11-11 01:41:59 | [diff] [blame] | 8512 | StaticSocketDataProvider ssl_bad_certificate; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8513 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8514 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8515 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8516 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8517 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8518 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8519 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 8520 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8521 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8522 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8523 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8524 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8525 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8526 | |
| 8527 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8528 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8529 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8530 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8531 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8532 | |
| 8533 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8534 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8535 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8536 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8537 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8538 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8539 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8540 | } |
| 8541 | |
| 8542 | // Test HTTPS connections to a site with a bad certificate, going through a |
| 8543 | // proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8544 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8545 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8546 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8547 | |
| 8548 | HttpRequestInfo request; |
| 8549 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8550 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8551 | request.traffic_annotation = |
| 8552 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8553 | |
| 8554 | MockWrite proxy_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8555 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8556 | "Host: www.example.org:443\r\n" |
| 8557 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8558 | }; |
| 8559 | |
| 8560 | MockRead proxy_reads[] = { |
| 8561 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8562 | MockRead(SYNCHRONOUS, OK) |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8563 | }; |
| 8564 | |
| 8565 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8566 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8567 | "Host: www.example.org:443\r\n" |
| 8568 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8569 | MockWrite("GET / HTTP/1.1\r\n" |
| 8570 | "Host: www.example.org\r\n" |
| 8571 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8572 | }; |
| 8573 | |
| 8574 | MockRead data_reads[] = { |
| 8575 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8576 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 8577 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8578 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8579 | MockRead(SYNCHRONOUS, OK), |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8580 | }; |
| 8581 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8582 | StaticSocketDataProvider ssl_bad_certificate(proxy_reads, proxy_writes); |
| 8583 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8584 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 8585 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8586 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8587 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 8588 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8589 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
| 8590 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8591 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8592 | TestCompletionCallback callback; |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8593 | |
| 8594 | for (int i = 0; i < 2; i++) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8595 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8596 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8597 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8598 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8599 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8600 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8601 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8602 | |
| 8603 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8604 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8605 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8606 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8607 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8608 | |
| 8609 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8610 | EXPECT_THAT(rv, IsOk()); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8611 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8612 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8613 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8614 | ASSERT_TRUE(response); |
[email protected] | bacff65 | 2009-03-31 17:50:33 | [diff] [blame] | 8615 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8616 | } |
| 8617 | } |
| 8618 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8619 | |
| 8620 | // Test HTTPS connections to a site, going through an HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8621 | TEST_F(HttpNetworkTransactionTest, HTTPSViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8622 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8623 | ProxyResolutionService::CreateFixedFromPacResult( |
| 8624 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8625 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8626 | session_deps_.net_log = &net_log; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8627 | |
| 8628 | HttpRequestInfo request; |
| 8629 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8630 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8631 | request.traffic_annotation = |
| 8632 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8633 | |
| 8634 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8635 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8636 | "Host: www.example.org:443\r\n" |
| 8637 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 8638 | MockWrite("GET / HTTP/1.1\r\n" |
| 8639 | "Host: www.example.org\r\n" |
| 8640 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8641 | }; |
| 8642 | |
| 8643 | MockRead data_reads[] = { |
| 8644 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 8645 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 8646 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 8647 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8648 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8649 | }; |
| 8650 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8651 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8652 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
| 8653 | SSLSocketDataProvider tunnel_ssl(ASYNC, OK); // SSL through the tunnel |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8654 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8655 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8656 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
| 8657 | session_deps_.socket_factory->AddSSLSocketDataProvider(&tunnel_ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8658 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8659 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8660 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8661 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8662 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8663 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8664 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8665 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8666 | |
| 8667 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8668 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8669 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8670 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8671 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8672 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 8673 | EXPECT_TRUE(response->proxy_server.is_https()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8674 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 8675 | EXPECT_EQ(200, response->headers->response_code()); |
| 8676 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 8677 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8678 | |
| 8679 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8680 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8681 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 8682 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 8683 | } |
| 8684 | |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8685 | // Test an HTTPS Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8686 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaHttpsProxy) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8687 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8688 | ProxyResolutionService::CreateFixedFromPacResult( |
| 8689 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8690 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8691 | session_deps_.net_log = &net_log; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8692 | |
| 8693 | HttpRequestInfo request; |
| 8694 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8695 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8696 | request.traffic_annotation = |
| 8697 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8698 | |
| 8699 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8700 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8701 | "Host: www.example.org:443\r\n" |
| 8702 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8703 | }; |
| 8704 | |
| 8705 | MockRead data_reads[] = { |
| 8706 | MockRead("HTTP/1.1 302 Redirect\r\n"), |
| 8707 | MockRead("Location: http://login.example.com/\r\n"), |
| 8708 | MockRead("Content-Length: 0\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8709 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8710 | }; |
| 8711 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8712 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8713 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8714 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8715 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8716 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8717 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8718 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8719 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8720 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8721 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8722 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8723 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8724 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8725 | |
| 8726 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8727 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8728 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8729 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8730 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8731 | |
| 8732 | EXPECT_EQ(302, response->headers->response_code()); |
| 8733 | std::string url; |
| 8734 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8735 | EXPECT_EQ("http://login.example.com/", url); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8736 | |
| 8737 | // In the case of redirects from proxies, HttpNetworkTransaction returns |
| 8738 | // timing for the proxy connection instead of the connection to the host, |
| 8739 | // and no send / receive times. |
| 8740 | // See HttpNetworkTransaction::OnHttpsProxyTunnelResponse. |
| 8741 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8742 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8743 | |
| 8744 | EXPECT_FALSE(load_timing_info.socket_reused); |
mikecirone | f22f981 | 2016-10-04 03:40:19 | [diff] [blame] | 8745 | EXPECT_NE(NetLogSource::kInvalidId, load_timing_info.socket_log_id); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 8746 | |
| 8747 | EXPECT_FALSE(load_timing_info.proxy_resolve_start.is_null()); |
| 8748 | EXPECT_LE(load_timing_info.proxy_resolve_start, |
| 8749 | load_timing_info.proxy_resolve_end); |
| 8750 | EXPECT_LE(load_timing_info.proxy_resolve_end, |
| 8751 | load_timing_info.connect_timing.connect_start); |
| 8752 | ExpectConnectTimingHasTimes( |
| 8753 | load_timing_info.connect_timing, |
| 8754 | CONNECT_TIMING_HAS_DNS_TIMES | CONNECT_TIMING_HAS_SSL_TIMES); |
| 8755 | |
| 8756 | EXPECT_TRUE(load_timing_info.send_start.is_null()); |
| 8757 | EXPECT_TRUE(load_timing_info.send_end.is_null()); |
| 8758 | EXPECT_TRUE(load_timing_info.receive_headers_end.is_null()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8759 | } |
| 8760 | |
| 8761 | // Test an HTTPS (SPDY) Proxy's ability to redirect a CONNECT request |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8762 | TEST_F(HttpNetworkTransactionTest, RedirectOfHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8763 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8764 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8765 | |
| 8766 | HttpRequestInfo request; |
| 8767 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8768 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8769 | request.traffic_annotation = |
| 8770 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8771 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8772 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8773 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8774 | spdy::SpdySerializedFrame goaway( |
| 8775 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8776 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8777 | CreateMockWrite(conn, 0, SYNCHRONOUS), |
| 8778 | CreateMockWrite(goaway, 2, SYNCHRONOUS), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8779 | }; |
| 8780 | |
| 8781 | static const char* const kExtraHeaders[] = { |
| 8782 | "location", |
| 8783 | "http://login.example.com/", |
| 8784 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8785 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8786 | "302", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8787 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8788 | CreateMockRead(resp, 1), MockRead(ASYNC, 0, 3), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8789 | }; |
| 8790 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8791 | SequencedSocketData data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8792 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8793 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8794 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8795 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8796 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8797 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8798 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8799 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8800 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8801 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8802 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8803 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8804 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8805 | |
| 8806 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8807 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8808 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8809 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 8810 | ASSERT_TRUE(response); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8811 | |
| 8812 | EXPECT_EQ(302, response->headers->response_code()); |
| 8813 | std::string url; |
| 8814 | EXPECT_TRUE(response->headers->IsRedirect(&url)); |
| 8815 | EXPECT_EQ("http://login.example.com/", url); |
| 8816 | } |
| 8817 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8818 | // Test that an HTTPS proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8819 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8820 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8821 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8822 | |
| 8823 | HttpRequestInfo request; |
| 8824 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8825 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8826 | request.traffic_annotation = |
| 8827 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8828 | |
| 8829 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 8830 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 8831 | "Host: www.example.org:443\r\n" |
| 8832 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8833 | }; |
| 8834 | |
| 8835 | MockRead data_reads[] = { |
| 8836 | MockRead("HTTP/1.1 404 Not Found\r\n"), |
| 8837 | MockRead("Content-Length: 23\r\n\r\n"), |
| 8838 | MockRead("The host does not exist"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8839 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8840 | }; |
| 8841 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8842 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8843 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8844 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8845 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8846 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8847 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8848 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8849 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8850 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8851 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8852 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8853 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8854 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8855 | |
| 8856 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8857 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8858 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8859 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8860 | } |
| 8861 | |
[email protected] | 4eddbc73 | 2012-08-09 05:40:17 | [diff] [blame] | 8862 | // Test that a SPDY proxy's response to a CONNECT request is filtered. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8863 | TEST_F(HttpNetworkTransactionTest, ErrorResponseToHttpsConnectViaSpdyProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8864 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 8865 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8866 | |
| 8867 | HttpRequestInfo request; |
| 8868 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8869 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8870 | request.traffic_annotation = |
| 8871 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8872 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8873 | spdy::SpdySerializedFrame conn(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8874 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8875 | spdy::SpdySerializedFrame rst( |
| 8876 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8877 | MockWrite data_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8878 | CreateMockWrite(conn, 0), CreateMockWrite(rst, 3), |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8879 | }; |
| 8880 | |
| 8881 | static const char* const kExtraHeaders[] = { |
| 8882 | "location", |
| 8883 | "http://login.example.com/", |
| 8884 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8885 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyReplyError( |
bnc | c9f762a | 2016-12-06 20:38:23 | [diff] [blame] | 8886 | "404", kExtraHeaders, arraysize(kExtraHeaders) / 2, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8887 | spdy::SpdySerializedFrame body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 8888 | spdy_util_.ConstructSpdyDataFrame(1, "The host does not exist", true)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8889 | MockRead data_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8890 | CreateMockRead(resp, 1), CreateMockRead(body, 2), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8891 | MockRead(ASYNC, 0, 4), // EOF |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8892 | }; |
| 8893 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8894 | SequencedSocketData data(data_reads, data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 8895 | SSLSocketDataProvider proxy_ssl(ASYNC, OK); // SSL to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8896 | proxy_ssl.next_proto = kProtoHTTP2; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8897 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8898 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 8899 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy_ssl); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8900 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 8901 | TestCompletionCallback callback; |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8902 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8903 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8904 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8905 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 8906 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8907 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8908 | |
| 8909 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 8910 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8911 | |
ttuttle | 960fcbf | 2016-04-19 13:26:32 | [diff] [blame] | 8912 | // TODO(juliatuttle): Anything else to check here? |
[email protected] | 511f6f5 | 2010-12-17 03:58:29 | [diff] [blame] | 8913 | } |
| 8914 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8915 | // Test the request-challenge-retry sequence for basic auth, through |
| 8916 | // a SPDY proxy over a single SPDY session. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 8917 | TEST_F(HttpNetworkTransactionTest, BasicAuthSpdyProxy) { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8918 | HttpRequestInfo request; |
| 8919 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8920 | request.url = GURL("https://www.example.org/"); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8921 | // when the no authentication data flag is set. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 8922 | request.load_flags = LOAD_DO_NOT_SEND_AUTH_DATA; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 8923 | request.traffic_annotation = |
| 8924 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8925 | |
| 8926 | // Configure against https proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 8927 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 8928 | ProxyResolutionService::CreateFixedFromPacResult( |
| 8929 | "HTTPS myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 8930 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8931 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 8932 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8933 | |
| 8934 | // Since we have proxy, should try to establish tunnel. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8935 | spdy::SpdySerializedFrame req(spdy_util_.ConstructSpdyConnect( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8936 | NULL, 0, 1, LOWEST, HostPortPair("www.example.org", 443))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8937 | spdy::SpdySerializedFrame rst( |
| 8938 | spdy_util_.ConstructSpdyRstStream(1, spdy::ERROR_CODE_CANCEL)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 8939 | spdy_util_.UpdateWithStreamDestruction(1); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8940 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 8941 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8942 | // be issuing -- the final header line contains the credentials. |
| 8943 | const char* const kAuthCredentials[] = { |
| 8944 | "proxy-authorization", "Basic Zm9vOmJhcg==", |
| 8945 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8946 | spdy::SpdySerializedFrame connect2(spdy_util_.ConstructSpdyConnect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 8947 | kAuthCredentials, arraysize(kAuthCredentials) / 2, 3, LOWEST, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 8948 | HostPortPair("www.example.org", 443))); |
| 8949 | // fetch https://www.example.org/ via HTTP |
| 8950 | const char get[] = |
| 8951 | "GET / HTTP/1.1\r\n" |
| 8952 | "Host: www.example.org\r\n" |
| 8953 | "Connection: keep-alive\r\n\r\n"; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8954 | spdy::SpdySerializedFrame wrapped_get( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 8955 | spdy_util_.ConstructSpdyDataFrame(3, get, false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8956 | |
| 8957 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8958 | CreateMockWrite(req, 0, ASYNC), CreateMockWrite(rst, 2, ASYNC), |
| 8959 | CreateMockWrite(connect2, 3), CreateMockWrite(wrapped_get, 5), |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8960 | }; |
| 8961 | |
| 8962 | // The proxy responds to the connect with a 407, using a persistent |
| 8963 | // connection. |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 8964 | const char kAuthStatus[] = "407"; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8965 | const char* const kAuthChallenge[] = { |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8966 | "proxy-authenticate", "Basic realm=\"MyRealm1\"", |
| 8967 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8968 | spdy::SpdySerializedFrame conn_auth_resp(spdy_util_.ConstructSpdyReplyError( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8969 | kAuthStatus, kAuthChallenge, arraysize(kAuthChallenge) / 2, 1)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8970 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8971 | spdy::SpdySerializedFrame conn_resp( |
| 8972 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8973 | const char resp[] = "HTTP/1.1 200 OK\r\n" |
| 8974 | "Content-Length: 5\r\n\r\n"; |
| 8975 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8976 | spdy::SpdySerializedFrame wrapped_get_resp( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 8977 | spdy_util_.ConstructSpdyDataFrame(3, resp, false)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 8978 | spdy::SpdySerializedFrame wrapped_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 8979 | spdy_util_.ConstructSpdyDataFrame(3, "hello", false)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8980 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 8981 | CreateMockRead(conn_auth_resp, 1, ASYNC), |
| 8982 | CreateMockRead(conn_resp, 4, ASYNC), |
| 8983 | CreateMockRead(wrapped_get_resp, 6, ASYNC), |
| 8984 | CreateMockRead(wrapped_body, 7, ASYNC), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 8985 | MockRead(ASYNC, OK, 8), // EOF. May or may not be read. |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8986 | }; |
| 8987 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 8988 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8989 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8990 | // Negotiate SPDY to the proxy |
| 8991 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 8992 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8993 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8994 | // Vanilla SSL to the server |
| 8995 | SSLSocketDataProvider server(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 8996 | session_deps_.socket_factory->AddSSLSocketDataProvider(&server); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 8997 | |
| 8998 | TestCompletionCallback callback1; |
| 8999 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9000 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9001 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9002 | |
| 9003 | int rv = trans->Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9004 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9005 | |
| 9006 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9007 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 9008 | TestNetLogEntry::List entries; |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9009 | log.GetEntries(&entries); |
| 9010 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 9011 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 9012 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9013 | ExpectLogContainsSomewhere( |
| 9014 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 9015 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 9016 | NetLogEventPhase::NONE); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9017 | |
| 9018 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9019 | ASSERT_TRUE(response); |
| 9020 | ASSERT_TRUE(response->headers); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9021 | EXPECT_EQ(407, response->headers->response_code()); |
| 9022 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9023 | EXPECT_TRUE(response->auth_challenge); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 9024 | EXPECT_TRUE(CheckBasicSecureProxyAuth(response->auth_challenge.get())); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9025 | |
| 9026 | TestCompletionCallback callback2; |
| 9027 | |
| 9028 | rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 9029 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9030 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9031 | |
| 9032 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9033 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9034 | |
| 9035 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9036 | ASSERT_TRUE(response); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9037 | |
| 9038 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9039 | EXPECT_EQ(200, response->headers->response_code()); |
| 9040 | EXPECT_EQ(5, response->headers->GetContentLength()); |
| 9041 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9042 | |
| 9043 | // The password prompt info should not be set. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9044 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9045 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9046 | LoadTimingInfo load_timing_info; |
| 9047 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9048 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9049 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9050 | |
[email protected] | 0c5fb72 | 2012-02-28 11:50:35 | [diff] [blame] | 9051 | trans.reset(); |
| 9052 | session->CloseAllConnections(); |
| 9053 | } |
| 9054 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9055 | // Test that an explicitly trusted SPDY proxy can push a resource from an |
| 9056 | // origin that is different from that of its associated resource. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9057 | TEST_F(HttpNetworkTransactionTest, CrossOriginSPDYProxyPush) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9058 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9059 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9060 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 9061 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9062 | HttpRequestInfo request; |
| 9063 | HttpRequestInfo push_request; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9064 | request.traffic_annotation = |
| 9065 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9066 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9067 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9068 | request.url = GURL("http://www.example.org/"); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9069 | push_request.method = "GET"; |
| 9070 | push_request.url = GURL("http://www.another-origin.com/foo.dat"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9071 | push_request.traffic_annotation = |
| 9072 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9073 | |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9074 | // Configure against https proxy server "myproxy:443". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9075 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9076 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9077 | "HTTPS myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9078 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9079 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9080 | |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 9081 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 9082 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9083 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9084 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9085 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9086 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9087 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9088 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9089 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9090 | |
| 9091 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9092 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9093 | CreateMockWrite(stream2_priority, 3, ASYNC), |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9094 | }; |
| 9095 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9096 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 9097 | NULL, 0, 2, 1, "http://www.another-origin.com/foo.dat")); |
| 9098 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9099 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9100 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9101 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9102 | spdy::SpdySerializedFrame stream1_body( |
| 9103 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9104 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9105 | spdy::SpdySerializedFrame stream2_body( |
Bence Béky | d74f438 | 2018-02-20 18:26:19 | [diff] [blame] | 9106 | spdy_util_.ConstructSpdyDataFrame(2, "pushed", true)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9107 | |
| 9108 | MockRead spdy_reads[] = { |
Bence Béky | 7bf9436 | 2018-01-10 13:19:36 | [diff] [blame] | 9109 | CreateMockRead(stream2_syn, 1, ASYNC), |
| 9110 | CreateMockRead(stream1_reply, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9111 | CreateMockRead(stream1_body, 4, ASYNC), |
| 9112 | CreateMockRead(stream2_body, 5, ASYNC), |
| 9113 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9114 | }; |
| 9115 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9116 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9117 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9118 | // Negotiate SPDY to the proxy |
| 9119 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9120 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9121 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9122 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9123 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9124 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9125 | TestCompletionCallback callback; |
| 9126 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9127 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9128 | |
| 9129 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9130 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9131 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9132 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9133 | auto push_trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9134 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 9135 | rv = push_trans->Start(&push_request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9136 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9137 | |
| 9138 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9139 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9140 | const HttpResponseInfo* push_response = push_trans->GetResponseInfo(); |
| 9141 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9142 | ASSERT_TRUE(response); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9143 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9144 | |
| 9145 | EXPECT_EQ(200, response->headers->response_code()); |
| 9146 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9147 | |
| 9148 | std::string response_data; |
| 9149 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9150 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9151 | EXPECT_EQ("hello!", response_data); |
| 9152 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9153 | LoadTimingInfo load_timing_info; |
| 9154 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 9155 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9156 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9157 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9158 | // Verify the pushed stream. |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9159 | EXPECT_TRUE(push_response->headers); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9160 | EXPECT_EQ(200, push_response->headers->response_code()); |
| 9161 | |
| 9162 | rv = ReadTransaction(push_trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9163 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9164 | EXPECT_EQ("pushed", response_data); |
| 9165 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9166 | LoadTimingInfo push_load_timing_info; |
| 9167 | EXPECT_TRUE(push_trans->GetLoadTimingInfo(&push_load_timing_info)); |
| 9168 | TestLoadTimingReusedWithPac(push_load_timing_info); |
| 9169 | // The transactions should share a socket ID, despite being for different |
| 9170 | // origins. |
| 9171 | EXPECT_EQ(load_timing_info.socket_log_id, |
| 9172 | push_load_timing_info.socket_log_id); |
| 9173 | |
[email protected] | 7c6f7ba | 2012-04-03 04:09:29 | [diff] [blame] | 9174 | trans.reset(); |
| 9175 | push_trans.reset(); |
| 9176 | session->CloseAllConnections(); |
| 9177 | } |
| 9178 | |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9179 | // Test that an explicitly trusted SPDY proxy cannot push HTTPS content. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9180 | TEST_F(HttpNetworkTransactionTest, CrossOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9181 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9182 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9183 | proxy_delegate->set_trusted_spdy_proxy(net::ProxyServer::FromURI( |
| 9184 | "https://myproxy:443", net::ProxyServer::SCHEME_HTTP)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9185 | HttpRequestInfo request; |
| 9186 | |
| 9187 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9188 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9189 | request.traffic_annotation = |
| 9190 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9191 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9192 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9193 | "https://myproxy:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9194 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9195 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9196 | |
| 9197 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 9198 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 9199 | proxy_delegate.get()); |
[email protected] | 61b4efc | 2012-04-27 18:12:50 | [diff] [blame] | 9200 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9201 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9202 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9203 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9204 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9205 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9206 | spdy::SpdySerializedFrame push_rst( |
| 9207 | spdy_util_.ConstructSpdyRstStream(2, spdy::ERROR_CODE_REFUSED_STREAM)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9208 | |
| 9209 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9210 | CreateMockWrite(stream1_syn, 0, ASYNC), CreateMockWrite(push_rst, 3), |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9211 | }; |
| 9212 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9213 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9214 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9215 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9216 | spdy::SpdySerializedFrame stream1_body( |
| 9217 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9218 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9219 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
bnc | b03b109 | 2016-04-06 11:19:55 | [diff] [blame] | 9220 | NULL, 0, 2, 1, "https://www.another-origin.com/foo.dat")); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9221 | |
| 9222 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9223 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 9224 | CreateMockRead(stream2_syn, 2, ASYNC), |
| 9225 | CreateMockRead(stream1_body, 4, ASYNC), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 9226 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), // Force a hang |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9227 | }; |
| 9228 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9229 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9230 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9231 | // Negotiate SPDY to the proxy |
| 9232 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9233 | proxy.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9234 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9235 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9236 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9237 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9238 | TestCompletionCallback callback; |
| 9239 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9240 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9241 | |
| 9242 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9243 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9244 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9245 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9246 | ASSERT_TRUE(response); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9247 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9248 | |
| 9249 | EXPECT_EQ(200, response->headers->response_code()); |
| 9250 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9251 | |
| 9252 | std::string response_data; |
| 9253 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9254 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 8c84319 | 2012-04-05 07:15:00 | [diff] [blame] | 9255 | EXPECT_EQ("hello!", response_data); |
| 9256 | |
| 9257 | trans.reset(); |
| 9258 | session->CloseAllConnections(); |
| 9259 | } |
| 9260 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9261 | // Test that an explicitly trusted SPDY proxy can push same-origin HTTPS |
| 9262 | // resources. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9263 | TEST_F(HttpNetworkTransactionTest, SameOriginProxyPushCorrectness) { |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9264 | // Configure the proxy delegate to allow cross-origin SPDY pushes. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9265 | auto proxy_delegate = std::make_unique<TestProxyDelegate>(); |
tbansal | 28e68f8 | 2016-02-04 02:56:15 | [diff] [blame] | 9266 | proxy_delegate->set_trusted_spdy_proxy( |
| 9267 | net::ProxyServer::FromURI("myproxy:70", net::ProxyServer::SCHEME_HTTP)); |
| 9268 | |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9269 | HttpRequestInfo request; |
| 9270 | |
| 9271 | request.method = "GET"; |
| 9272 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9273 | request.traffic_annotation = |
| 9274 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9275 | |
| 9276 | // Configure against https proxy server "myproxy:70". |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9277 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9278 | "https://myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9279 | BoundTestNetLog log; |
| 9280 | session_deps_.net_log = log.bound().net_log(); |
| 9281 | |
| 9282 | // Enable cross-origin push. |
Eric Roman | 3d8546a | 2018-09-10 17:00:52 | [diff] [blame] | 9283 | session_deps_.proxy_resolution_service->SetProxyDelegate( |
| 9284 | proxy_delegate.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9285 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9286 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9287 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9288 | spdy::SpdySerializedFrame stream1_syn( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 9289 | spdy_util_.ConstructSpdyGet("http://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9290 | spdy::SpdySerializedFrame stream2_priority( |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9291 | spdy_util_.ConstructSpdyPriority(2, 1, IDLE, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9292 | |
| 9293 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9294 | CreateMockWrite(stream1_syn, 0, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9295 | CreateMockWrite(stream2_priority, 3, ASYNC), |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9296 | }; |
| 9297 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9298 | spdy::SpdySerializedFrame stream1_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9299 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9300 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9301 | spdy::SpdySerializedFrame stream2_syn(spdy_util_.ConstructSpdyPush( |
Bence Béky | 096cf05 | 2017-08-08 23:55:33 | [diff] [blame] | 9302 | nullptr, 0, 2, 1, "http://www.example.org/foo.dat")); |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 9303 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9304 | spdy::SpdySerializedFrame stream1_body( |
| 9305 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9306 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9307 | spdy::SpdySerializedFrame stream2_reply( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 9308 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9309 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 9310 | spdy::SpdySerializedFrame stream2_body( |
| 9311 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9312 | |
| 9313 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 9314 | CreateMockRead(stream1_reply, 1, ASYNC), |
| 9315 | CreateMockRead(stream2_syn, 2, ASYNC), |
tombergan | 5d22c18 | 2017-01-11 02:05:35 | [diff] [blame] | 9316 | CreateMockRead(stream1_body, 4, ASYNC), |
| 9317 | CreateMockRead(stream2_body, 5, ASYNC), |
| 9318 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 6), // Force a hang |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9319 | }; |
| 9320 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9321 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9322 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 9323 | // Negotiate SPDY to the proxy |
| 9324 | SSLSocketDataProvider proxy(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 9325 | proxy.next_proto = kProtoHTTP2; |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9326 | session_deps_.socket_factory->AddSSLSocketDataProvider(&proxy); |
| 9327 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 9328 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 9329 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9330 | TestCompletionCallback callback; |
| 9331 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9332 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9333 | |
| 9334 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9335 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9336 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 9337 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9338 | ASSERT_TRUE(response); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9339 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 9340 | |
| 9341 | EXPECT_EQ(200, response->headers->response_code()); |
| 9342 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 9343 | |
| 9344 | std::string response_data; |
| 9345 | rv = ReadTransaction(trans.get(), &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9346 | EXPECT_THAT(rv, IsOk()); |
tbansal | 8ef1d3e | 2016-02-03 04:05:42 | [diff] [blame] | 9347 | EXPECT_EQ("hello!", response_data); |
| 9348 | |
| 9349 | trans.reset(); |
| 9350 | session->CloseAllConnections(); |
| 9351 | } |
| 9352 | |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9353 | // Test HTTPS connections to a site with a bad certificate, going through an |
| 9354 | // HTTPS proxy |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9355 | TEST_F(HttpNetworkTransactionTest, HTTPSBadCertificateViaHttpsProxy) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9356 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9357 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9358 | |
| 9359 | HttpRequestInfo request; |
| 9360 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9361 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9362 | request.traffic_annotation = |
| 9363 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9364 | |
| 9365 | // Attempt to fetch the URL from a server with a bad cert |
| 9366 | MockWrite bad_cert_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9367 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9368 | "Host: www.example.org:443\r\n" |
| 9369 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9370 | }; |
| 9371 | |
| 9372 | MockRead bad_cert_reads[] = { |
| 9373 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9374 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9375 | }; |
| 9376 | |
| 9377 | // Attempt to fetch the URL with a good cert |
| 9378 | MockWrite good_data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9379 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9380 | "Host: www.example.org:443\r\n" |
| 9381 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 9382 | MockWrite("GET / HTTP/1.1\r\n" |
| 9383 | "Host: www.example.org\r\n" |
| 9384 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9385 | }; |
| 9386 | |
| 9387 | MockRead good_cert_reads[] = { |
| 9388 | MockRead("HTTP/1.0 200 Connected\r\n\r\n"), |
| 9389 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9390 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9391 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9392 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9393 | }; |
| 9394 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9395 | StaticSocketDataProvider ssl_bad_certificate(bad_cert_reads, bad_cert_writes); |
| 9396 | StaticSocketDataProvider data(good_cert_reads, good_data_writes); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9397 | SSLSocketDataProvider ssl_bad(ASYNC, ERR_CERT_AUTHORITY_INVALID); |
| 9398 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9399 | |
| 9400 | // SSL to the proxy, then CONNECT request, then SSL with bad certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9401 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9402 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_bad_certificate); |
| 9403 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_bad); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9404 | |
| 9405 | // SSL to the proxy, then CONNECT request, then valid SSL certificate |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9406 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 9407 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 9408 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9409 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9410 | TestCompletionCallback callback; |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9411 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9412 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9413 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9414 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9415 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9416 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9417 | |
| 9418 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9419 | EXPECT_THAT(rv, IsError(ERR_CERT_AUTHORITY_INVALID)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9420 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9421 | rv = trans.RestartIgnoringLastError(callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9422 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9423 | |
| 9424 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9425 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9426 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9427 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9428 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9429 | ASSERT_TRUE(response); |
[email protected] | 2df19bb | 2010-08-25 20:13:46 | [diff] [blame] | 9430 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 9431 | } |
| 9432 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9433 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgent) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9434 | HttpRequestInfo request; |
| 9435 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9436 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9437 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 9438 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9439 | request.traffic_annotation = |
| 9440 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9441 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9442 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9443 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9444 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9445 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9446 | MockWrite( |
| 9447 | "GET / HTTP/1.1\r\n" |
| 9448 | "Host: www.example.org\r\n" |
| 9449 | "Connection: keep-alive\r\n" |
| 9450 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9451 | }; |
| 9452 | |
| 9453 | // Lastly, the server responds with the actual content. |
| 9454 | MockRead data_reads[] = { |
| 9455 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9456 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9457 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9458 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9459 | }; |
| 9460 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9461 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9462 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9463 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9464 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9465 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9466 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9467 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9468 | |
| 9469 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9470 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9471 | } |
| 9472 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9473 | TEST_F(HttpNetworkTransactionTest, BuildRequest_UserAgentOverTunnel) { |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9474 | HttpRequestInfo request; |
| 9475 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9476 | request.url = GURL("https://www.example.org/"); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9477 | request.extra_headers.SetHeader(HttpRequestHeaders::kUserAgent, |
| 9478 | "Chromium Ultra Awesome X Edition"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9479 | request.traffic_annotation = |
| 9480 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9481 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9482 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9483 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9484 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9485 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9486 | |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9487 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 9488 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 9489 | "Host: www.example.org:443\r\n" |
| 9490 | "Proxy-Connection: keep-alive\r\n" |
| 9491 | "User-Agent: Chromium Ultra Awesome X Edition\r\n\r\n"), |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9492 | }; |
| 9493 | MockRead data_reads[] = { |
| 9494 | // Return an error, so the transaction stops here (this test isn't |
| 9495 | // interested in the rest). |
| 9496 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n"), |
| 9497 | MockRead("Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 9498 | MockRead("Proxy-Connection: close\r\n\r\n"), |
| 9499 | }; |
| 9500 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9501 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9502 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9503 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9504 | TestCompletionCallback callback; |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9505 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9506 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9507 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9508 | |
| 9509 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9510 | EXPECT_THAT(rv, IsOk()); |
[email protected] | da81f13 | 2010-08-18 23:39:29 | [diff] [blame] | 9511 | } |
| 9512 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9513 | TEST_F(HttpNetworkTransactionTest, BuildRequest_Referer) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9514 | HttpRequestInfo request; |
| 9515 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9516 | request.url = GURL("http://www.example.org/"); |
[email protected] | c1045010 | 2011-06-27 09:06:16 | [diff] [blame] | 9517 | request.extra_headers.SetHeader(HttpRequestHeaders::kReferer, |
| 9518 | "http://the.previous.site.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9519 | request.traffic_annotation = |
| 9520 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9521 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9522 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9523 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9524 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9525 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9526 | MockWrite( |
| 9527 | "GET / HTTP/1.1\r\n" |
| 9528 | "Host: www.example.org\r\n" |
| 9529 | "Connection: keep-alive\r\n" |
| 9530 | "Referer: http://the.previous.site.com/\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9531 | }; |
| 9532 | |
| 9533 | // Lastly, the server responds with the actual content. |
| 9534 | MockRead data_reads[] = { |
| 9535 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9536 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9537 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9538 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9539 | }; |
| 9540 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9541 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9542 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9543 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9544 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9545 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9546 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9547 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9548 | |
| 9549 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9550 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9551 | } |
| 9552 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9553 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PostContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9554 | HttpRequestInfo request; |
| 9555 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9556 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9557 | request.traffic_annotation = |
| 9558 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9559 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9560 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9561 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9562 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9563 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9564 | MockWrite( |
| 9565 | "POST / HTTP/1.1\r\n" |
| 9566 | "Host: www.example.org\r\n" |
| 9567 | "Connection: keep-alive\r\n" |
| 9568 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9569 | }; |
| 9570 | |
| 9571 | // Lastly, the server responds with the actual content. |
| 9572 | MockRead data_reads[] = { |
| 9573 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9574 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9575 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9576 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9577 | }; |
| 9578 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9579 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9580 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9581 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9582 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9583 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9584 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9585 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9586 | |
| 9587 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9588 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9589 | } |
| 9590 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9591 | TEST_F(HttpNetworkTransactionTest, BuildRequest_PutContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9592 | HttpRequestInfo request; |
| 9593 | request.method = "PUT"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9594 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9595 | request.traffic_annotation = |
| 9596 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9597 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9598 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9599 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9600 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9601 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9602 | MockWrite( |
| 9603 | "PUT / HTTP/1.1\r\n" |
| 9604 | "Host: www.example.org\r\n" |
| 9605 | "Connection: keep-alive\r\n" |
| 9606 | "Content-Length: 0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9607 | }; |
| 9608 | |
| 9609 | // Lastly, the server responds with the actual content. |
| 9610 | MockRead data_reads[] = { |
| 9611 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9612 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9613 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9614 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9615 | }; |
| 9616 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9617 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9618 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9619 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9620 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9621 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9622 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9623 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9624 | |
| 9625 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9626 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9627 | } |
| 9628 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9629 | TEST_F(HttpNetworkTransactionTest, BuildRequest_HeadContentLengthZero) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9630 | HttpRequestInfo request; |
| 9631 | request.method = "HEAD"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9632 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9633 | request.traffic_annotation = |
| 9634 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9635 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9636 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9637 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9638 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9639 | MockWrite data_writes[] = { |
csharrison | f473dd19 | 2015-08-18 13:54:13 | [diff] [blame] | 9640 | MockWrite("HEAD / HTTP/1.1\r\n" |
| 9641 | "Host: www.example.org\r\n" |
| 9642 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9643 | }; |
| 9644 | |
| 9645 | // Lastly, the server responds with the actual content. |
| 9646 | MockRead data_reads[] = { |
| 9647 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9648 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9649 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9650 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9651 | }; |
| 9652 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9653 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9654 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9655 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9656 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9657 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9658 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9659 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9660 | |
| 9661 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9662 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9663 | } |
| 9664 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9665 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlNoCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9666 | HttpRequestInfo request; |
| 9667 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9668 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9669 | request.load_flags = LOAD_BYPASS_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9670 | request.traffic_annotation = |
| 9671 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9672 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9673 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9674 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9675 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9676 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9677 | MockWrite( |
| 9678 | "GET / HTTP/1.1\r\n" |
| 9679 | "Host: www.example.org\r\n" |
| 9680 | "Connection: keep-alive\r\n" |
| 9681 | "Pragma: no-cache\r\n" |
| 9682 | "Cache-Control: no-cache\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9683 | }; |
| 9684 | |
| 9685 | // Lastly, the server responds with the actual content. |
| 9686 | MockRead data_reads[] = { |
| 9687 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9688 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9689 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9690 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9691 | }; |
| 9692 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9693 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9694 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9695 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9696 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9697 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9698 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9699 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9700 | |
| 9701 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9702 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9703 | } |
| 9704 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9705 | TEST_F(HttpNetworkTransactionTest, BuildRequest_CacheControlValidateCache) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9706 | HttpRequestInfo request; |
| 9707 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9708 | request.url = GURL("http://www.example.org/"); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9709 | request.load_flags = LOAD_VALIDATE_CACHE; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9710 | request.traffic_annotation = |
| 9711 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9712 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9713 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9714 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9715 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9716 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9717 | MockWrite( |
| 9718 | "GET / HTTP/1.1\r\n" |
| 9719 | "Host: www.example.org\r\n" |
| 9720 | "Connection: keep-alive\r\n" |
| 9721 | "Cache-Control: max-age=0\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9722 | }; |
| 9723 | |
| 9724 | // Lastly, the server responds with the actual content. |
| 9725 | MockRead data_reads[] = { |
| 9726 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9727 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9728 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9729 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9730 | }; |
| 9731 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9732 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9733 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9734 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9735 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9736 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9737 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9738 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9739 | |
| 9740 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9741 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9742 | } |
| 9743 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9744 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeaders) { |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9745 | HttpRequestInfo request; |
| 9746 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9747 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9748 | request.extra_headers.SetHeader("FooHeader", "Bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9749 | request.traffic_annotation = |
| 9750 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9751 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9752 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9753 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9754 | |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9755 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9756 | MockWrite( |
| 9757 | "GET / HTTP/1.1\r\n" |
| 9758 | "Host: www.example.org\r\n" |
| 9759 | "Connection: keep-alive\r\n" |
| 9760 | "FooHeader: Bar\r\n\r\n"), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9761 | }; |
| 9762 | |
| 9763 | // Lastly, the server responds with the actual content. |
| 9764 | MockRead data_reads[] = { |
| 9765 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9766 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9767 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9768 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9769 | }; |
| 9770 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9771 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9772 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9773 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9774 | TestCompletionCallback callback; |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9775 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9776 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9777 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9778 | |
| 9779 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9780 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 1c773ea1 | 2009-04-28 19:58:42 | [diff] [blame] | 9781 | } |
| 9782 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9783 | TEST_F(HttpNetworkTransactionTest, BuildRequest_ExtraHeadersStripped) { |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9784 | HttpRequestInfo request; |
| 9785 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9786 | request.url = GURL("http://www.example.org/"); |
[email protected] | 8c76ae2 | 2010-04-20 22:15:43 | [diff] [blame] | 9787 | request.extra_headers.SetHeader("referer", "www.foo.com"); |
| 9788 | request.extra_headers.SetHeader("hEllo", "Kitty"); |
| 9789 | request.extra_headers.SetHeader("FoO", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9790 | request.traffic_annotation = |
| 9791 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9792 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9793 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9794 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9795 | |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9796 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9797 | MockWrite( |
| 9798 | "GET / HTTP/1.1\r\n" |
| 9799 | "Host: www.example.org\r\n" |
| 9800 | "Connection: keep-alive\r\n" |
| 9801 | "referer: www.foo.com\r\n" |
| 9802 | "hEllo: Kitty\r\n" |
| 9803 | "FoO: bar\r\n\r\n"), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9804 | }; |
| 9805 | |
| 9806 | // Lastly, the server responds with the actual content. |
| 9807 | MockRead data_reads[] = { |
| 9808 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9809 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 9810 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9811 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9812 | }; |
| 9813 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9814 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9815 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9816 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9817 | TestCompletionCallback callback; |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9818 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9819 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9820 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9821 | |
| 9822 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9823 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 270c641 | 2010-03-29 22:02:47 | [diff] [blame] | 9824 | } |
| 9825 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9826 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9827 | HttpRequestInfo request; |
| 9828 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9829 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9830 | request.traffic_annotation = |
| 9831 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9832 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9833 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9834 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9835 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9836 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9837 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9838 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9839 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9840 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9841 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9842 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9843 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9844 | |
| 9845 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9846 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9847 | MockWrite( |
| 9848 | "GET / HTTP/1.1\r\n" |
| 9849 | "Host: www.example.org\r\n" |
| 9850 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9851 | |
| 9852 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9853 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9854 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9855 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9856 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9857 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9858 | }; |
| 9859 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9860 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9861 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9862 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9863 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9864 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9865 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9866 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9867 | |
| 9868 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9869 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9870 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9871 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9872 | ASSERT_TRUE(response); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9873 | |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9874 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9875 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9876 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9877 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9878 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 9879 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9880 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9881 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9882 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9883 | EXPECT_EQ("Payload", response_text); |
| 9884 | } |
| 9885 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9886 | TEST_F(HttpNetworkTransactionTest, SOCKS4_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9887 | HttpRequestInfo request; |
| 9888 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9889 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9890 | request.traffic_annotation = |
| 9891 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 9892 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 9893 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9894 | ProxyResolutionService::CreateFixedFromPacResult( |
| 9895 | "SOCKS myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9896 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9897 | session_deps_.net_log = &net_log; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9898 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9899 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9900 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9901 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9902 | unsigned char write_buffer[] = { 0x04, 0x01, 0x01, 0xBB, 127, 0, 0, 1, 0 }; |
| 9903 | unsigned char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9904 | |
| 9905 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9906 | MockWrite(ASYNC, reinterpret_cast<char*>(write_buffer), |
| 9907 | arraysize(write_buffer)), |
| 9908 | MockWrite( |
| 9909 | "GET / HTTP/1.1\r\n" |
| 9910 | "Host: www.example.org\r\n" |
| 9911 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 9912 | |
| 9913 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 9914 | MockRead(ASYNC, reinterpret_cast<char*>(read_buffer), |
| 9915 | arraysize(read_buffer)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9916 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9917 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9918 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9919 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9920 | }; |
| 9921 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9922 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9923 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9924 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 9925 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9926 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9927 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 9928 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9929 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9930 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9931 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9932 | |
| 9933 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9934 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9935 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9936 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9937 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9938 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 9939 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 9940 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9941 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9942 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 9943 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS4, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9944 | |
| 9945 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9946 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9947 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 9948 | EXPECT_EQ("Payload", response_text); |
| 9949 | } |
| 9950 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 9951 | TEST_F(HttpNetworkTransactionTest, SOCKS4_HTTP_GET_no_PAC) { |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9952 | HttpRequestInfo request; |
| 9953 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9954 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 9955 | request.traffic_annotation = |
| 9956 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9957 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 9958 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 9959 | "socks4://myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 9960 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9961 | session_deps_.net_log = &net_log; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9962 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 9963 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9964 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9965 | |
| 9966 | char write_buffer[] = { 0x04, 0x01, 0x00, 0x50, 127, 0, 0, 1, 0 }; |
| 9967 | char read_buffer[] = { 0x00, 0x5A, 0x00, 0x00, 0, 0, 0, 0 }; |
| 9968 | |
| 9969 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 9970 | MockWrite(ASYNC, write_buffer, arraysize(write_buffer)), |
| 9971 | MockWrite( |
| 9972 | "GET / HTTP/1.1\r\n" |
| 9973 | "Host: www.example.org\r\n" |
| 9974 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9975 | |
| 9976 | MockRead data_reads[] = { |
| 9977 | MockRead(ASYNC, read_buffer, arraysize(read_buffer)), |
| 9978 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 9979 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 9980 | MockRead("Payload"), |
| 9981 | MockRead(SYNCHRONOUS, OK) |
| 9982 | }; |
| 9983 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 9984 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 9985 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9986 | |
| 9987 | TestCompletionCallback callback; |
| 9988 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 9989 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9990 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9991 | |
| 9992 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 9993 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9994 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9995 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 9996 | ASSERT_TRUE(response); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 9997 | |
| 9998 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 9999 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10000 | TestLoadTimingNotReused(load_timing_info, |
| 10001 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10002 | |
| 10003 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10004 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10005 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10006 | EXPECT_EQ("Payload", response_text); |
| 10007 | } |
| 10008 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10009 | TEST_F(HttpNetworkTransactionTest, SOCKS5_HTTP_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10010 | HttpRequestInfo request; |
| 10011 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10012 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10013 | request.traffic_annotation = |
| 10014 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10015 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10016 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10017 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10018 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10019 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10020 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10021 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10022 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10023 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10024 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10025 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 10026 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10027 | const char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10028 | 0x05, // Version |
| 10029 | 0x01, // Command (CONNECT) |
| 10030 | 0x00, // Reserved. |
| 10031 | 0x03, // Address type (DOMAINNAME). |
| 10032 | 0x0F, // Length of domain (15) |
| 10033 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 10034 | '.', 'o', 'r', 'g', 0x00, 0x50, // 16-bit port (80) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10035 | }; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10036 | const char kSOCKS5OkResponse[] = |
| 10037 | { 0x05, 0x00, 0x00, 0x01, 127, 0, 0, 1, 0x00, 0x50 }; |
| 10038 | |
| 10039 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10040 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 10041 | MockWrite(ASYNC, kSOCKS5OkRequest, arraysize(kSOCKS5OkRequest)), |
| 10042 | MockWrite( |
| 10043 | "GET / HTTP/1.1\r\n" |
| 10044 | "Host: www.example.org\r\n" |
| 10045 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10046 | |
| 10047 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 10048 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 10049 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10050 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10051 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10052 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10053 | MockRead(SYNCHRONOUS, OK) |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10054 | }; |
| 10055 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10056 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10057 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10058 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10059 | TestCompletionCallback callback; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10060 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10061 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10062 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10063 | |
| 10064 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10065 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10066 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10067 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10068 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10069 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10070 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10071 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10072 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10073 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10074 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 10075 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10076 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10077 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10078 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10079 | EXPECT_EQ("Payload", response_text); |
| 10080 | } |
| 10081 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10082 | TEST_F(HttpNetworkTransactionTest, SOCKS5_SSL_GET) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10083 | HttpRequestInfo request; |
| 10084 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10085 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10086 | request.traffic_annotation = |
| 10087 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10088 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10089 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10090 | ProxyResolutionService::CreateFixedFromPacResult( |
| 10091 | "SOCKS5 myproxy:1080", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 10092 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10093 | session_deps_.net_log = &net_log; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10094 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10095 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10096 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10097 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10098 | const char kSOCKS5GreetRequest[] = { 0x05, 0x01, 0x00 }; |
| 10099 | const char kSOCKS5GreetResponse[] = { 0x05, 0x00 }; |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10100 | const unsigned char kSOCKS5OkRequest[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10101 | 0x05, // Version |
| 10102 | 0x01, // Command (CONNECT) |
| 10103 | 0x00, // Reserved. |
| 10104 | 0x03, // Address type (DOMAINNAME). |
| 10105 | 0x0F, // Length of domain (15) |
| 10106 | 'w', 'w', 'w', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', // Domain string |
| 10107 | '.', 'o', 'r', 'g', 0x01, 0xBB, // 16-bit port (443) |
[email protected] | f209dba | 2009-12-18 00:24:37 | [diff] [blame] | 10108 | }; |
| 10109 | |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10110 | const char kSOCKS5OkResponse[] = |
| 10111 | { 0x05, 0x00, 0x00, 0x01, 0, 0, 0, 0, 0x00, 0x00 }; |
| 10112 | |
| 10113 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10114 | MockWrite(ASYNC, kSOCKS5GreetRequest, arraysize(kSOCKS5GreetRequest)), |
| 10115 | MockWrite(ASYNC, reinterpret_cast<const char*>(kSOCKS5OkRequest), |
| 10116 | arraysize(kSOCKS5OkRequest)), |
| 10117 | MockWrite( |
| 10118 | "GET / HTTP/1.1\r\n" |
| 10119 | "Host: www.example.org\r\n" |
| 10120 | "Connection: keep-alive\r\n\r\n")}; |
[email protected] | e0c27be | 2009-07-15 13:09:35 | [diff] [blame] | 10121 | |
| 10122 | MockRead data_reads[] = { |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 10123 | MockRead(ASYNC, kSOCKS5GreetResponse, arraysize(kSOCKS5GreetResponse)), |
| 10124 | MockRead(ASYNC, kSOCKS5OkResponse, arraysize(kSOCKS5OkResponse)), |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10125 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 10126 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n\r\n"), |
| 10127 | MockRead("Payload"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10128 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10129 | }; |
| 10130 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10131 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10132 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10133 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10134 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10135 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10136 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10137 | TestCompletionCallback callback; |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10138 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10139 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10140 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10141 | |
| 10142 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10143 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10144 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10145 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10146 | ASSERT_TRUE(response); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 10147 | EXPECT_EQ(ProxyServer::SCHEME_SOCKS5, response->proxy_server.scheme()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10148 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10149 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10150 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 10151 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 10152 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 10153 | |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10154 | std::string response_text; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10155 | rv = ReadTransaction(&trans, &response_text); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10156 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3cd1724 | 2009-06-23 02:59:02 | [diff] [blame] | 10157 | EXPECT_EQ("Payload", response_text); |
| 10158 | } |
| 10159 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10160 | namespace { |
| 10161 | |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10162 | // Tests that for connection endpoints the group names are correctly set. |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10163 | |
| 10164 | struct GroupNameTest { |
| 10165 | std::string proxy_server; |
| 10166 | std::string url; |
| 10167 | std::string expected_group_name; |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10168 | bool ssl; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10169 | }; |
| 10170 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10171 | std::unique_ptr<HttpNetworkSession> SetupSessionForGroupNameTests( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10172 | SpdySessionDependencies* session_deps_) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10173 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10174 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 10175 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 10176 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 10177 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 10178 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 10179 | http_server_properties->SetHttp2AlternativeService( |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10180 | url::SchemeHostPort("https", "host.with.alternate", 443), |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 10181 | alternative_service, expiration); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10182 | |
| 10183 | return session; |
| 10184 | } |
| 10185 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10186 | int GroupNameTransactionHelper(const std::string& url, |
| 10187 | HttpNetworkSession* session) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10188 | HttpRequestInfo request; |
| 10189 | request.method = "GET"; |
| 10190 | request.url = GURL(url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10191 | request.traffic_annotation = |
| 10192 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10193 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10194 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10195 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10196 | TestCompletionCallback callback; |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10197 | |
| 10198 | // We do not complete this request, the dtor will clean the transaction up. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10199 | return trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10200 | } |
| 10201 | |
[email protected] | 448d4ca5 | 2012-03-04 04:12:23 | [diff] [blame] | 10202 | } // namespace |
| 10203 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10204 | TEST_F(HttpNetworkTransactionTest, GroupNameForDirectConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10205 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10206 | { |
| 10207 | "", // unused |
| 10208 | "http://www.example.org/direct", |
| 10209 | "www.example.org:80", |
| 10210 | false, |
| 10211 | }, |
| 10212 | { |
| 10213 | "", // unused |
| 10214 | "http://[2001:1418:13:1::25]/direct", |
| 10215 | "[2001:1418:13:1::25]:80", |
| 10216 | false, |
| 10217 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10218 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10219 | // SSL Tests |
| 10220 | { |
| 10221 | "", // unused |
| 10222 | "https://www.example.org/direct_ssl", |
| 10223 | "ssl/www.example.org:443", |
| 10224 | true, |
| 10225 | }, |
| 10226 | { |
| 10227 | "", // unused |
| 10228 | "https://[2001:1418:13:1::25]/direct", |
| 10229 | "ssl/[2001:1418:13:1::25]:443", |
| 10230 | true, |
| 10231 | }, |
| 10232 | { |
| 10233 | "", // unused |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10234 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10235 | "ssl/host.with.alternate:443", |
| 10236 | true, |
| 10237 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10238 | }; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 10239 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10240 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10241 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10242 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 10243 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10244 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10245 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10246 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10247 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10248 | CaptureGroupNameTransportSocketPool* transport_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10249 | new CaptureGroupNameTransportSocketPool(nullptr, nullptr); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10250 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10251 | new CaptureGroupNameSSLSocketPool(nullptr, nullptr); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10252 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 10253 | mock_pool_manager->SetTransportSocketPool(transport_conn_pool); |
| 10254 | mock_pool_manager->SetSSLSocketPool(ssl_conn_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10255 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10256 | |
| 10257 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10258 | GroupNameTransactionHelper(tests[i].url, session.get())); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 10259 | if (tests[i].ssl) { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10260 | EXPECT_EQ(tests[i].expected_group_name, |
| 10261 | ssl_conn_pool->last_group_name_received()); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 10262 | } else { |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10263 | EXPECT_EQ(tests[i].expected_group_name, |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 10264 | transport_conn_pool->last_group_name_received()); |
Tarun Bansal | 162eabe5 | 2018-01-20 01:16:39 | [diff] [blame] | 10265 | } |
| 10266 | // When SSL proxy is in use, socket must be requested from |ssl_conn_pool|. |
| 10267 | EXPECT_EQ(tests[i].ssl, ssl_conn_pool->socket_requested()); |
| 10268 | // When SSL proxy is not in use, socket must be requested from |
| 10269 | // |transport_conn_pool|. |
| 10270 | EXPECT_EQ(!tests[i].ssl, transport_conn_pool->socket_requested()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10271 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10272 | } |
| 10273 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10274 | TEST_F(HttpNetworkTransactionTest, GroupNameForHTTPProxyConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10275 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10276 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10277 | "http_proxy", "http://www.example.org/http_proxy_normal", |
| 10278 | "http_proxy/www.example.org:80", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10279 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10280 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10281 | // SSL Tests |
| 10282 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10283 | "http_proxy", "https://www.example.org/http_connect_ssl", |
| 10284 | "http_proxy/ssl/www.example.org:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10285 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 10286 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10287 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10288 | "http_proxy", "https://host.with.alternate/direct", |
| 10289 | "http_proxy/ssl/host.with.alternate:443", true, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10290 | }, |
[email protected] | 4549925 | 2013-01-23 17:12:56 | [diff] [blame] | 10291 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10292 | { |
Matt Menke | d1eb6d4 | 2018-01-17 04:54:06 | [diff] [blame] | 10293 | "http_proxy", "ftp://ftp.google.com/http_proxy_normal", |
| 10294 | "http_proxy/ftp/ftp.google.com:21", false, |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10295 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10296 | }; |
| 10297 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10298 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10299 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10300 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 10301 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10302 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10303 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10304 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10305 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10306 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10307 | HostPortPair proxy_host("http_proxy", 80); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10308 | CaptureGroupNameHttpProxySocketPool* http_proxy_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10309 | new CaptureGroupNameHttpProxySocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10310 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10311 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10312 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 10313 | mock_pool_manager->SetSocketPoolForHTTPProxy( |
| 10314 | proxy_host, base::WrapUnique(http_proxy_pool)); |
| 10315 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 10316 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10317 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10318 | |
| 10319 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10320 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10321 | if (tests[i].ssl) |
| 10322 | EXPECT_EQ(tests[i].expected_group_name, |
| 10323 | ssl_conn_pool->last_group_name_received()); |
| 10324 | else |
| 10325 | EXPECT_EQ(tests[i].expected_group_name, |
| 10326 | http_proxy_pool->last_group_name_received()); |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10327 | } |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10328 | } |
| 10329 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10330 | TEST_F(HttpNetworkTransactionTest, GroupNameForSOCKSConnections) { |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10331 | const GroupNameTest tests[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10332 | { |
| 10333 | "socks4://socks_proxy:1080", |
| 10334 | "http://www.example.org/socks4_direct", |
| 10335 | "socks4/www.example.org:80", |
| 10336 | false, |
| 10337 | }, |
| 10338 | { |
| 10339 | "socks5://socks_proxy:1080", |
| 10340 | "http://www.example.org/socks5_direct", |
| 10341 | "socks5/www.example.org:80", |
| 10342 | false, |
| 10343 | }, |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10344 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10345 | // SSL Tests |
| 10346 | { |
| 10347 | "socks4://socks_proxy:1080", |
| 10348 | "https://www.example.org/socks4_ssl", |
| 10349 | "socks4/ssl/www.example.org:443", |
| 10350 | true, |
| 10351 | }, |
| 10352 | { |
| 10353 | "socks5://socks_proxy:1080", |
| 10354 | "https://www.example.org/socks5_ssl", |
| 10355 | "socks5/ssl/www.example.org:443", |
| 10356 | true, |
| 10357 | }, |
[email protected] | af3490e | 2010-10-16 21:02:29 | [diff] [blame] | 10358 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10359 | { |
| 10360 | "socks4://socks_proxy:1080", |
bnc | aa60ff40 | 2016-06-22 19:12:42 | [diff] [blame] | 10361 | "https://host.with.alternate/direct", |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10362 | "socks4/ssl/host.with.alternate:443", |
| 10363 | true, |
| 10364 | }, |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10365 | }; |
| 10366 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 10367 | for (size_t i = 0; i < arraysize(tests); ++i) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 10368 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10369 | ProxyResolutionService::CreateFixed(tests[i].proxy_server, |
| 10370 | TRAFFIC_ANNOTATION_FOR_TESTS); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10371 | std::unique_ptr<HttpNetworkSession> session( |
bnc | a9b9e22 | 2016-07-11 20:10:40 | [diff] [blame] | 10372 | SetupSessionForGroupNameTests(&session_deps_)); |
[email protected] | 8b114dd7 | 2011-03-25 05:33:02 | [diff] [blame] | 10373 | |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10374 | HttpNetworkSessionPeer peer(session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10375 | |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10376 | HostPortPair proxy_host("socks_proxy", 1080); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10377 | CaptureGroupNameSOCKSSocketPool* socks_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10378 | new CaptureGroupNameSOCKSSocketPool(NULL, NULL); |
[email protected] | 2431756e | 2010-09-29 20:26:13 | [diff] [blame] | 10379 | CaptureGroupNameSSLSocketPool* ssl_conn_pool = |
[email protected] | 9e1bdd3 | 2011-02-03 21:48:34 | [diff] [blame] | 10380 | new CaptureGroupNameSSLSocketPool(NULL, NULL); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10381 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
avi | adef344 | 2016-10-03 18:50:39 | [diff] [blame] | 10382 | mock_pool_manager->SetSocketPoolForSOCKSProxy( |
| 10383 | proxy_host, base::WrapUnique(socks_conn_pool)); |
| 10384 | mock_pool_manager->SetSocketPoolForSSLWithProxy( |
| 10385 | proxy_host, base::WrapUnique(ssl_conn_pool)); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 10386 | peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10387 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10388 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10389 | |
[email protected] | 2d731a3 | 2010-04-29 01:04:06 | [diff] [blame] | 10390 | EXPECT_EQ(ERR_IO_PENDING, |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 10391 | GroupNameTransactionHelper(tests[i].url, session.get())); |
[email protected] | e60e47a | 2010-07-14 03:37:18 | [diff] [blame] | 10392 | if (tests[i].ssl) |
| 10393 | EXPECT_EQ(tests[i].expected_group_name, |
| 10394 | ssl_conn_pool->last_group_name_received()); |
| 10395 | else |
| 10396 | EXPECT_EQ(tests[i].expected_group_name, |
| 10397 | socks_conn_pool->last_group_name_received()); |
[email protected] | 04e5be3 | 2009-06-26 20:00:31 | [diff] [blame] | 10398 | } |
| 10399 | } |
| 10400 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10401 | TEST_F(HttpNetworkTransactionTest, ReconsiderProxyAfterFailedConnection) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10402 | HttpRequestInfo request; |
| 10403 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10404 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10405 | request.traffic_annotation = |
| 10406 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10407 | |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10408 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10409 | "myproxy:70;foobar:80", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10410 | |
[email protected] | 6971906 | 2010-01-05 20:09:21 | [diff] [blame] | 10411 | // This simulates failure resolving all hostnames; that means we will fail |
| 10412 | // connecting to both proxies (myproxy:70 and foobar:80). |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10413 | session_deps_.host_resolver->rules()->AddSimulatedFailure("*"); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10414 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10415 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10416 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10417 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10418 | TestCompletionCallback callback; |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10419 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10420 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10421 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10422 | |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10423 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10424 | EXPECT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 9172a98 | 2009-06-06 00:30:25 | [diff] [blame] | 10425 | } |
| 10426 | |
Miriam Gershenson | 2a01b16 | 2018-03-22 22:54:47 | [diff] [blame] | 10427 | // LOAD_BYPASS_CACHE should trigger the host cache bypass. |
| 10428 | TEST_F(HttpNetworkTransactionTest, BypassHostCacheOnRefresh) { |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10429 | // Issue a request, asking to bypass the cache(s). |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10430 | HttpRequestInfo request_info; |
| 10431 | request_info.method = "GET"; |
Miriam Gershenson | 2a01b16 | 2018-03-22 22:54:47 | [diff] [blame] | 10432 | request_info.load_flags = LOAD_BYPASS_CACHE; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10433 | request_info.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10434 | request_info.traffic_annotation = |
| 10435 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10436 | |
[email protected] | a2c2fb9 | 2009-07-18 07:31:04 | [diff] [blame] | 10437 | // Select a host resolver that does caching. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10438 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
[email protected] | b59ff37 | 2009-07-15 22:04:32 | [diff] [blame] | 10439 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10440 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10441 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10442 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10443 | // 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] | 10444 | AddressList addrlist; |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 10445 | TestCompletionCallback callback; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10446 | std::unique_ptr<HostResolver::Request> request1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10447 | int rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10448 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10449 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request1, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10450 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10451 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 10452 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10453 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10454 | |
| 10455 | // Verify that it was added to host cache, by doing a subsequent async lookup |
| 10456 | // and confirming it completes synchronously. |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10457 | std::unique_ptr<HostResolver::Request> request2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10458 | rv = session_deps_.host_resolver->Resolve( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10459 | HostResolver::RequestInfo(HostPortPair("www.example.org", 80)), |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 10460 | DEFAULT_PRIORITY, &addrlist, callback.callback(), &request2, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10461 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10462 | ASSERT_THAT(rv, IsOk()); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10463 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10464 | // 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] | 10465 | // we can tell if the next lookup hit the cache, or the "network". |
| 10466 | // (cache --> success, "network" --> failure). |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10467 | session_deps_.host_resolver->rules()->AddSimulatedFailure("www.example.org"); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10468 | |
| 10469 | // Connect up a mock socket which will fail with ERR_UNEXPECTED during the |
| 10470 | // 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] | 10471 | MockRead data_reads[] = { MockRead(SYNCHRONOUS, ERR_UNEXPECTED) }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10472 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10473 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10474 | |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10475 | // Run the request. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10476 | rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10477 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10478 | rv = callback.WaitForResult(); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10479 | |
| 10480 | // If we bypassed the cache, we would have gotten a failure while resolving |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10481 | // "www.example.org". |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10482 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 3b9cca4 | 2009-06-16 01:08:28 | [diff] [blame] | 10483 | } |
| 10484 | |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10485 | // Make sure we can handle an error when writing the request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10486 | TEST_F(HttpNetworkTransactionTest, RequestWriteError) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10487 | HttpRequestInfo request; |
| 10488 | request.method = "GET"; |
| 10489 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10490 | request.traffic_annotation = |
| 10491 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10492 | |
| 10493 | MockWrite write_failure[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10494 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10495 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10496 | StaticSocketDataProvider data(base::span<MockRead>(), write_failure); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10497 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10498 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10499 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10500 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10501 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10502 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10503 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10504 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10505 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10506 | |
| 10507 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10508 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10509 | |
| 10510 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10511 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10512 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10513 | } |
| 10514 | |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10515 | // Check that a connection closed after the start of the headers finishes ok. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10516 | TEST_F(HttpNetworkTransactionTest, ConnectionClosedAfterStartOfHeaders) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10517 | HttpRequestInfo request; |
| 10518 | request.method = "GET"; |
| 10519 | request.url = GURL("http://www.foo.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10520 | request.traffic_annotation = |
| 10521 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10522 | |
| 10523 | MockRead data_reads[] = { |
| 10524 | MockRead("HTTP/1."), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10525 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10526 | }; |
| 10527 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10528 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10529 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10530 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10531 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10532 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10533 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10534 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10535 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10536 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10537 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10538 | |
| 10539 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10540 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10541 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10542 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10543 | ASSERT_TRUE(response); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10544 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10545 | EXPECT_TRUE(response->headers); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10546 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10547 | |
| 10548 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10549 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10550 | EXPECT_THAT(rv, IsOk()); |
zmo | 9528c9f4 | 2015-08-04 22:12:08 | [diff] [blame] | 10551 | EXPECT_EQ("", response_data); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10552 | |
| 10553 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10554 | EXPECT_TRUE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 10555 | EXPECT_LT(0u, endpoint.address().size()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10556 | } |
| 10557 | |
| 10558 | // Make sure that a dropped connection while draining the body for auth |
| 10559 | // restart does the right thing. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10560 | TEST_F(HttpNetworkTransactionTest, DrainResetOK) { |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10561 | HttpRequestInfo request; |
| 10562 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10563 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10564 | request.traffic_annotation = |
| 10565 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10566 | |
| 10567 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10568 | MockWrite( |
| 10569 | "GET / HTTP/1.1\r\n" |
| 10570 | "Host: www.example.org\r\n" |
| 10571 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10572 | }; |
| 10573 | |
| 10574 | MockRead data_reads1[] = { |
| 10575 | MockRead("HTTP/1.1 401 Unauthorized\r\n"), |
| 10576 | MockRead("WWW-Authenticate: Basic realm=\"MyRealm1\"\r\n"), |
| 10577 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 10578 | MockRead("Content-Length: 14\r\n\r\n"), |
| 10579 | MockRead("Unauth"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10580 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10581 | }; |
| 10582 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10583 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10584 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10585 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10586 | // After calling trans.RestartWithAuth(), this is the request we should |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10587 | // be issuing -- the final header line contains the credentials. |
| 10588 | MockWrite data_writes2[] = { |
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 | "Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10594 | }; |
| 10595 | |
| 10596 | // Lastly, the server responds with the actual content. |
| 10597 | MockRead data_reads2[] = { |
| 10598 | MockRead("HTTP/1.1 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] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10602 | }; |
| 10603 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10604 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10605 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10606 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10607 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10608 | TestCompletionCallback callback1; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10609 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10610 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10611 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10612 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10613 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10614 | |
| 10615 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10616 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10617 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10618 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10619 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10620 | EXPECT_TRUE(CheckBasicServerAuth(response->auth_challenge.get())); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10621 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10622 | TestCompletionCallback callback2; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10623 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10624 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10625 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10626 | |
| 10627 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10628 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10629 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10630 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10631 | ASSERT_TRUE(response); |
| 10632 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10633 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 10634 | } |
| 10635 | |
| 10636 | // Test HTTPS connections going through a proxy that sends extra data. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10637 | TEST_F(HttpNetworkTransactionTest, HTTPSViaProxyWithExtraData) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 10638 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 10639 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10640 | |
| 10641 | HttpRequestInfo request; |
| 10642 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10643 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10644 | request.traffic_annotation = |
| 10645 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10646 | |
| 10647 | MockRead proxy_reads[] = { |
| 10648 | MockRead("HTTP/1.0 200 Connected\r\n\r\nExtra data"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10649 | MockRead(SYNCHRONOUS, OK) |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10650 | }; |
| 10651 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10652 | StaticSocketDataProvider data(proxy_reads, base::span<MockWrite>()); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10653 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10654 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10655 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10656 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10657 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10658 | TestCompletionCallback callback; |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10659 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10660 | session_deps_.socket_factory->ResetNextMockIndexes(); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10661 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10662 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10663 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10664 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10665 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10666 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10667 | |
| 10668 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10669 | EXPECT_THAT(rv, IsError(ERR_TUNNEL_CONNECTION_FAILED)); |
[email protected] | 0877e3d | 2009-10-17 22:29:57 | [diff] [blame] | 10670 | } |
| 10671 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10672 | TEST_F(HttpNetworkTransactionTest, LargeContentLengthThenClose) { |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10673 | HttpRequestInfo request; |
| 10674 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10675 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10676 | request.traffic_annotation = |
| 10677 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10678 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10679 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10680 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 10681 | |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10682 | MockRead data_reads[] = { |
| 10683 | 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] | 10684 | MockRead(SYNCHRONOUS, OK), |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10685 | }; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10686 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10687 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10688 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10689 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10690 | TestCompletionCallback callback; |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10691 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10692 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10693 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10694 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10695 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10696 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10697 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10698 | ASSERT_TRUE(response); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10699 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10700 | EXPECT_TRUE(response->headers); |
[email protected] | 9492e4a | 2010-02-24 00:58:46 | [diff] [blame] | 10701 | EXPECT_EQ("HTTP/1.0 200 OK", response->headers->GetStatusLine()); |
| 10702 | |
| 10703 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10704 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10705 | EXPECT_THAT(rv, IsError(ERR_CONTENT_LENGTH_MISMATCH)); |
[email protected] | e22e136 | 2009-11-23 21:31:12 | [diff] [blame] | 10706 | } |
| 10707 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10708 | TEST_F(HttpNetworkTransactionTest, UploadFileSmallerThanLength) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10709 | base::FilePath temp_file_path; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10710 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file_path)); |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10711 | const uint64_t kFakeSize = 100000; // file is actually blank |
[email protected] | d9896165 | 2012-09-11 20:27:21 | [diff] [blame] | 10712 | UploadFileElementReader::ScopedOverridingContentLengthForTests |
| 10713 | overriding_content_length(kFakeSize); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10714 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10715 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10716 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10717 | base::ThreadTaskRunnerHandle::Get().get(), temp_file_path, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10718 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10719 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10720 | |
| 10721 | HttpRequestInfo request; |
| 10722 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10723 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10724 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10725 | request.traffic_annotation = |
| 10726 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10727 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10728 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10729 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10730 | |
| 10731 | MockRead data_reads[] = { |
| 10732 | MockRead("HTTP/1.0 200 OK\r\n\r\n"), |
| 10733 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 10734 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10735 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10736 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10737 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10738 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10739 | TestCompletionCallback callback; |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10740 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10741 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10742 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10743 | |
| 10744 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10745 | EXPECT_THAT(rv, IsError(ERR_UPLOAD_FILE_CHANGED)); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10746 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10747 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10748 | ASSERT_TRUE(response); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10749 | |
maksim.sisov | e869bf5 | 2016-06-23 17:11:52 | [diff] [blame] | 10750 | EXPECT_FALSE(response->headers); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10751 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10752 | base::DeleteFile(temp_file_path, false); |
[email protected] | 95d88ffe | 2010-02-04 21:25:33 | [diff] [blame] | 10753 | } |
| 10754 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10755 | TEST_F(HttpNetworkTransactionTest, UploadUnreadableFile) { |
[email protected] | 6cdfd7f | 2013-02-08 20:40:15 | [diff] [blame] | 10756 | base::FilePath temp_file; |
[email protected] | 03d9afc0 | 2013-12-03 17:55:52 | [diff] [blame] | 10757 | ASSERT_TRUE(base::CreateTemporaryFile(&temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10758 | std::string temp_file_content("Unreadable file."); |
lazyboy | 8df84fc | 2017-04-12 02:12:48 | [diff] [blame] | 10759 | ASSERT_EQ(static_cast<int>(temp_file_content.length()), |
| 10760 | base::WriteFile(temp_file, temp_file_content.c_str(), |
| 10761 | temp_file_content.length())); |
[email protected] | 92be8eb | 2014-08-07 22:57:11 | [diff] [blame] | 10762 | ASSERT_TRUE(base::MakeFileUnreadable(temp_file)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10763 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10764 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10765 | element_readers.push_back(std::make_unique<UploadFileElementReader>( |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10766 | base::ThreadTaskRunnerHandle::Get().get(), temp_file, 0, |
ricea | 2deef68 | 2016-09-09 08:04:07 | [diff] [blame] | 10767 | std::numeric_limits<uint64_t>::max(), base::Time())); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10768 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10769 | |
| 10770 | HttpRequestInfo request; |
| 10771 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10772 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10773 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10774 | request.traffic_annotation = |
| 10775 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 329b68b | 2012-11-14 17:54:27 | [diff] [blame] | 10776 | |
[email protected] | 999dd8c | 2013-11-12 06:45:54 | [diff] [blame] | 10777 | // If we try to upload an unreadable file, the transaction should fail. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10778 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10779 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10780 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10781 | StaticSocketDataProvider data; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10782 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10783 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10784 | TestCompletionCallback callback; |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10785 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10786 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10787 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10788 | |
| 10789 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10790 | EXPECT_THAT(rv, IsError(ERR_ACCESS_DENIED)); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10791 | |
[email protected] | dd3aa79 | 2013-07-16 19:10:23 | [diff] [blame] | 10792 | base::DeleteFile(temp_file, false); |
[email protected] | 6624b462 | 2010-03-29 19:58:36 | [diff] [blame] | 10793 | } |
| 10794 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10795 | TEST_F(HttpNetworkTransactionTest, CancelDuringInitRequestBody) { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10796 | class FakeUploadElementReader : public UploadElementReader { |
| 10797 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 10798 | FakeUploadElementReader() = default; |
| 10799 | ~FakeUploadElementReader() override = default; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10800 | |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10801 | CompletionOnceCallback TakeCallback() { return std::move(callback_); } |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10802 | |
| 10803 | // UploadElementReader overrides: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10804 | int Init(CompletionOnceCallback callback) override { |
| 10805 | callback_ = std::move(callback); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10806 | return ERR_IO_PENDING; |
| 10807 | } |
avi | bf0746c | 2015-12-09 19:53:14 | [diff] [blame] | 10808 | uint64_t GetContentLength() const override { return 0; } |
| 10809 | uint64_t BytesRemaining() const override { return 0; } |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 10810 | int Read(IOBuffer* buf, |
| 10811 | int buf_length, |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10812 | CompletionOnceCallback callback) override { |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10813 | return ERR_FAILED; |
| 10814 | } |
| 10815 | |
| 10816 | private: |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10817 | CompletionOnceCallback callback_; |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10818 | }; |
| 10819 | |
| 10820 | FakeUploadElementReader* fake_reader = new FakeUploadElementReader; |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10821 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 10822 | element_readers.push_back(base::WrapUnique(fake_reader)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 10823 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10824 | |
| 10825 | HttpRequestInfo request; |
| 10826 | request.method = "POST"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10827 | request.url = GURL("http://www.example.org/upload"); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10828 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10829 | request.traffic_annotation = |
| 10830 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10831 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10832 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 10833 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 10834 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10835 | |
| 10836 | StaticSocketDataProvider data; |
| 10837 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 10838 | |
| 10839 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10840 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10841 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 10842 | base::RunLoop().RunUntilIdle(); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10843 | |
| 10844 | // Transaction is pending on request body initialization. |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10845 | CompletionOnceCallback init_callback = fake_reader->TakeCallback(); |
| 10846 | ASSERT_FALSE(init_callback.is_null()); |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10847 | |
| 10848 | // Return Init()'s result after the transaction gets destroyed. |
| 10849 | trans.reset(); |
Matt Menke | cc1d3a90 | 2018-02-05 18:27:33 | [diff] [blame] | 10850 | std::move(init_callback).Run(OK); // Should not crash. |
[email protected] | 02cad5d | 2013-10-02 08:14:03 | [diff] [blame] | 10851 | } |
| 10852 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10853 | // Tests that changes to Auth realms are treated like auth rejections. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 10854 | TEST_F(HttpNetworkTransactionTest, ChangeAuthRealms) { |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10855 | HttpRequestInfo request; |
| 10856 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10857 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 10858 | request.traffic_annotation = |
| 10859 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10860 | |
| 10861 | // First transaction will request a resource and receive a Basic challenge |
| 10862 | // with realm="first_realm". |
| 10863 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10864 | MockWrite( |
| 10865 | "GET / HTTP/1.1\r\n" |
| 10866 | "Host: www.example.org\r\n" |
| 10867 | "Connection: keep-alive\r\n" |
| 10868 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10869 | }; |
| 10870 | MockRead data_reads1[] = { |
| 10871 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10872 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10873 | "\r\n"), |
| 10874 | }; |
| 10875 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10876 | // After calling trans.RestartWithAuth(), provide an Authentication header |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10877 | // for first_realm. The server will reject and provide a challenge with |
| 10878 | // second_realm. |
| 10879 | MockWrite data_writes2[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10880 | MockWrite( |
| 10881 | "GET / HTTP/1.1\r\n" |
| 10882 | "Host: www.example.org\r\n" |
| 10883 | "Connection: keep-alive\r\n" |
| 10884 | "Authorization: Basic Zmlyc3Q6YmF6\r\n" |
| 10885 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10886 | }; |
| 10887 | MockRead data_reads2[] = { |
| 10888 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10889 | "WWW-Authenticate: Basic realm=\"second_realm\"\r\n" |
| 10890 | "\r\n"), |
| 10891 | }; |
| 10892 | |
| 10893 | // This again fails, and goes back to first_realm. Make sure that the |
| 10894 | // entry is removed from cache. |
| 10895 | MockWrite data_writes3[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10896 | MockWrite( |
| 10897 | "GET / HTTP/1.1\r\n" |
| 10898 | "Host: www.example.org\r\n" |
| 10899 | "Connection: keep-alive\r\n" |
| 10900 | "Authorization: Basic c2Vjb25kOmZvdQ==\r\n" |
| 10901 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10902 | }; |
| 10903 | MockRead data_reads3[] = { |
| 10904 | MockRead("HTTP/1.1 401 Unauthorized\r\n" |
| 10905 | "WWW-Authenticate: Basic realm=\"first_realm\"\r\n" |
| 10906 | "\r\n"), |
| 10907 | }; |
| 10908 | |
| 10909 | // Try one last time (with the correct password) and get the resource. |
| 10910 | MockWrite data_writes4[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 10911 | MockWrite( |
| 10912 | "GET / HTTP/1.1\r\n" |
| 10913 | "Host: www.example.org\r\n" |
| 10914 | "Connection: keep-alive\r\n" |
| 10915 | "Authorization: Basic Zmlyc3Q6YmFy\r\n" |
| 10916 | "\r\n"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10917 | }; |
| 10918 | MockRead data_reads4[] = { |
| 10919 | MockRead("HTTP/1.1 200 OK\r\n" |
| 10920 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10921 | "Content-Length: 5\r\n" |
| 10922 | "\r\n" |
| 10923 | "hello"), |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10924 | }; |
| 10925 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 10926 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
| 10927 | StaticSocketDataProvider data2(data_reads2, data_writes2); |
| 10928 | StaticSocketDataProvider data3(data_reads3, data_writes3); |
| 10929 | StaticSocketDataProvider data4(data_reads4, data_writes4); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 10930 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 10931 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 10932 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
| 10933 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10934 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10935 | TestCompletionCallback callback1; |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10936 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 10937 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10938 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 10939 | |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10940 | // Issue the first request with Authorize headers. There should be a |
| 10941 | // password prompt for first_realm waiting to be filled in after the |
| 10942 | // transaction completes. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 10943 | int rv = trans.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10944 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10945 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10946 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10947 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10948 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10949 | const AuthChallengeInfo* challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10950 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10951 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10952 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10953 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10954 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10955 | |
| 10956 | // Issue the second request with an incorrect password. There should be a |
| 10957 | // password prompt for second_realm waiting to be filled in after the |
| 10958 | // transaction completes. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10959 | TestCompletionCallback callback2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10960 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBaz), |
| 10961 | callback2.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10962 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10963 | rv = callback2.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10964 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10965 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10966 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10967 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10968 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10969 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10970 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10971 | EXPECT_EQ("second_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10972 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10973 | |
| 10974 | // Issue the third request with another incorrect password. There should be |
| 10975 | // a password prompt for first_realm waiting to be filled in. If the password |
| 10976 | // prompt is not present, it indicates that the HttpAuthCacheEntry for |
| 10977 | // first_realm was not correctly removed. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10978 | TestCompletionCallback callback3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10979 | rv = trans.RestartWithAuth(AuthCredentials(kSecond, kFou), |
| 10980 | callback3.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10981 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10982 | rv = callback3.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10983 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10984 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10985 | ASSERT_TRUE(response); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10986 | challenge = response->auth_challenge.get(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 10987 | ASSERT_TRUE(challenge); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10988 | EXPECT_FALSE(challenge->is_proxy); |
asanka | 098c009 | 2016-06-16 20:18:43 | [diff] [blame] | 10989 | EXPECT_EQ("http://www.example.org", challenge->challenger.Serialize()); |
[email protected] | 79cb5c1 | 2011-09-12 13:12:04 | [diff] [blame] | 10990 | EXPECT_EQ("first_realm", challenge->realm); |
aberent | bba302d | 2015-12-03 10:20:19 | [diff] [blame] | 10991 | EXPECT_EQ(kBasicAuthScheme, challenge->scheme); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10992 | |
| 10993 | // Issue the fourth request with the correct password and username. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 10994 | TestCompletionCallback callback4; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 10995 | rv = trans.RestartWithAuth(AuthCredentials(kFirst, kBar), |
| 10996 | callback4.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10997 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 10998 | rv = callback4.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 10999 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11000 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11001 | ASSERT_TRUE(response); |
| 11002 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | aeefc9e8 | 2010-02-19 16:18:27 | [diff] [blame] | 11003 | } |
| 11004 | |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11005 | // Regression test for https://crbug.com/754395. |
| 11006 | TEST_F(HttpNetworkTransactionTest, IgnoreAltSvcWithInvalidCert) { |
| 11007 | MockRead data_reads[] = { |
| 11008 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11009 | MockRead(kAlternativeServiceHttpHeader), |
| 11010 | MockRead("\r\n"), |
| 11011 | MockRead("hello world"), |
| 11012 | MockRead(SYNCHRONOUS, OK), |
| 11013 | }; |
| 11014 | |
| 11015 | HttpRequestInfo request; |
| 11016 | request.method = "GET"; |
| 11017 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11018 | request.traffic_annotation = |
| 11019 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11020 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11021 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11022 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11023 | |
| 11024 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11025 | ssl.ssl_info.cert = |
| 11026 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11027 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 11028 | ssl.ssl_info.cert_status = CERT_STATUS_COMMON_NAME_INVALID; |
Bence Béky | 230ac61 | 2017-08-30 19:17:08 | [diff] [blame] | 11029 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11030 | |
| 11031 | TestCompletionCallback callback; |
| 11032 | |
| 11033 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11034 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 11035 | |
| 11036 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 11037 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11038 | |
| 11039 | url::SchemeHostPort test_server(request.url); |
| 11040 | HttpServerProperties* http_server_properties = |
| 11041 | session->http_server_properties(); |
| 11042 | EXPECT_TRUE( |
| 11043 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11044 | |
| 11045 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 11046 | |
| 11047 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 11048 | ASSERT_TRUE(response); |
| 11049 | ASSERT_TRUE(response->headers); |
| 11050 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11051 | EXPECT_FALSE(response->was_fetched_via_spdy); |
| 11052 | EXPECT_FALSE(response->was_alpn_negotiated); |
| 11053 | |
| 11054 | std::string response_data; |
| 11055 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 11056 | EXPECT_EQ("hello world", response_data); |
| 11057 | |
| 11058 | EXPECT_TRUE( |
| 11059 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
| 11060 | } |
| 11061 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11062 | TEST_F(HttpNetworkTransactionTest, HonorAlternativeServiceHeader) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11063 | MockRead data_reads[] = { |
| 11064 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11065 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11066 | MockRead("\r\n"), |
| 11067 | MockRead("hello world"), |
| 11068 | MockRead(SYNCHRONOUS, OK), |
| 11069 | }; |
| 11070 | |
| 11071 | HttpRequestInfo request; |
| 11072 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11073 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11074 | request.traffic_annotation = |
| 11075 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11076 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11077 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11078 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11079 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11080 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11081 | ssl.ssl_info.cert = |
| 11082 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11083 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11084 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11085 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11086 | TestCompletionCallback callback; |
| 11087 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11088 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11089 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11090 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11091 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11092 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11093 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11094 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11095 | HttpServerProperties* http_server_properties = |
| 11096 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11097 | EXPECT_TRUE( |
| 11098 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11099 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11100 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11101 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11102 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11103 | ASSERT_TRUE(response); |
| 11104 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11105 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11106 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11107 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11108 | |
| 11109 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11110 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11111 | EXPECT_EQ("hello world", response_data); |
| 11112 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11113 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 11114 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 11115 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 11116 | AlternativeService alternative_service(kProtoHTTP2, "mail.example.org", 443); |
| 11117 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11118 | alternative_service_info_vector[0].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11119 | } |
| 11120 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11121 | // Regression test for https://crbug.com/615497. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11122 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11123 | DoNotParseAlternativeServiceHeaderOnInsecureRequest) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11124 | MockRead data_reads[] = { |
| 11125 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11126 | MockRead(kAlternativeServiceHttpHeader), |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11127 | MockRead("\r\n"), |
| 11128 | MockRead("hello world"), |
| 11129 | MockRead(SYNCHRONOUS, OK), |
| 11130 | }; |
| 11131 | |
| 11132 | HttpRequestInfo request; |
| 11133 | request.method = "GET"; |
| 11134 | request.url = GURL("http://www.example.org/"); |
| 11135 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11136 | request.traffic_annotation = |
| 11137 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11138 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11139 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11140 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11141 | |
| 11142 | TestCompletionCallback callback; |
| 11143 | |
| 11144 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11145 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11146 | |
| 11147 | url::SchemeHostPort test_server(request.url); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11148 | HttpServerProperties* http_server_properties = |
| 11149 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11150 | EXPECT_TRUE( |
| 11151 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11152 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11153 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11154 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11155 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11156 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11157 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11158 | ASSERT_TRUE(response); |
| 11159 | ASSERT_TRUE(response->headers); |
| 11160 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11161 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11162 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11163 | |
| 11164 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11165 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11166 | EXPECT_EQ("hello world", response_data); |
| 11167 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11168 | EXPECT_TRUE( |
| 11169 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11170 | } |
| 11171 | |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 11172 | // HTTP/2 Alternative Services should be disabled by default. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11173 | // TODO(bnc): Remove when https://crbug.com/615413 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11174 | TEST_F(HttpNetworkTransactionTest, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11175 | DisableHTTP2AlternativeServicesWithDifferentHost) { |
bnc | a86731e | 2017-04-17 12:31:28 | [diff] [blame] | 11176 | session_deps_.enable_http2_alternative_service = false; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11177 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11178 | HttpRequestInfo request; |
| 11179 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11180 | request.url = GURL("https://www.example.org/"); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11181 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11182 | request.traffic_annotation = |
| 11183 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11184 | |
| 11185 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11186 | StaticSocketDataProvider first_data; |
| 11187 | first_data.set_connect_data(mock_connect); |
| 11188 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11189 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11190 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11191 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11192 | |
| 11193 | MockRead data_reads[] = { |
| 11194 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 11195 | MockRead(ASYNC, OK), |
| 11196 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11197 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11198 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 11199 | |
| 11200 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11201 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11202 | HttpServerProperties* http_server_properties = |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11203 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11204 | AlternativeService alternative_service(kProtoHTTP2, "different.example.org", |
| 11205 | 444); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11206 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11207 | http_server_properties->SetHttp2AlternativeService( |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11208 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 11209 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11210 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11211 | TestCompletionCallback callback; |
| 11212 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11213 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11214 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11215 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 11216 | } |
| 11217 | |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11218 | // Regression test for https://crbug.com/615497: |
| 11219 | // Alternative Services should be disabled for http origin. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11220 | TEST_F(HttpNetworkTransactionTest, |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11221 | DisableAlternativeServicesForInsecureOrigin) { |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11222 | HttpRequestInfo request; |
| 11223 | request.method = "GET"; |
| 11224 | request.url = GURL("http://www.example.org/"); |
| 11225 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11226 | request.traffic_annotation = |
| 11227 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11228 | |
| 11229 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11230 | StaticSocketDataProvider first_data; |
| 11231 | first_data.set_connect_data(mock_connect); |
| 11232 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
| 11233 | |
| 11234 | MockRead data_reads[] = { |
| 11235 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 11236 | MockRead(ASYNC, OK), |
| 11237 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11238 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11239 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
| 11240 | |
| 11241 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 11242 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11243 | HttpServerProperties* http_server_properties = |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11244 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11245 | AlternativeService alternative_service(kProtoHTTP2, "", 444); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11246 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11247 | http_server_properties->SetHttp2AlternativeService( |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11248 | url::SchemeHostPort(request.url), alternative_service, expiration); |
| 11249 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11250 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11251 | TestCompletionCallback callback; |
| 11252 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11253 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11254 | // Alternative service is not used, request fails. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11255 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | e3dd56f | 2016-06-01 10:37:11 | [diff] [blame] | 11256 | } |
| 11257 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11258 | TEST_F(HttpNetworkTransactionTest, ClearAlternativeServices) { |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11259 | // Set an alternative service for origin. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11260 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11261 | HttpServerProperties* http_server_properties = |
| 11262 | session->http_server_properties(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11263 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11264 | AlternativeService alternative_service(kProtoQUIC, "", 80); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11265 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11266 | http_server_properties->SetQuicAlternativeService( |
| 11267 | test_server, alternative_service, expiration, |
| 11268 | session->params().quic_supported_versions); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11269 | EXPECT_EQ( |
| 11270 | 1u, |
| 11271 | http_server_properties->GetAlternativeServiceInfos(test_server).size()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11272 | |
| 11273 | // Send a clear header. |
| 11274 | MockRead data_reads[] = { |
| 11275 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 11276 | MockRead("Alt-Svc: clear\r\n"), |
| 11277 | MockRead("\r\n"), |
| 11278 | MockRead("hello world"), |
| 11279 | MockRead(SYNCHRONOUS, OK), |
| 11280 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11281 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11282 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11283 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11284 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11285 | ssl.ssl_info.cert = |
| 11286 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11287 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11288 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11289 | |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11290 | HttpRequestInfo request; |
| 11291 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11292 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11293 | request.traffic_annotation = |
| 11294 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11295 | |
| 11296 | TestCompletionCallback callback; |
| 11297 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11298 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11299 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11300 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11301 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11302 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11303 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11304 | ASSERT_TRUE(response); |
| 11305 | ASSERT_TRUE(response->headers); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11306 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11307 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11308 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11309 | |
| 11310 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11311 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11312 | EXPECT_EQ("hello world", response_data); |
| 11313 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11314 | EXPECT_TRUE( |
| 11315 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | 4f57585 | 2015-10-14 18:35:08 | [diff] [blame] | 11316 | } |
| 11317 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11318 | TEST_F(HttpNetworkTransactionTest, HonorMultipleAlternativeServiceHeaders) { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11319 | MockRead data_reads[] = { |
| 11320 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11321 | MockRead("Alt-Svc: h2=\"www.example.com:443\","), |
| 11322 | MockRead("h2=\":1234\"\r\n\r\n"), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11323 | MockRead("hello world"), |
| 11324 | MockRead(SYNCHRONOUS, OK), |
| 11325 | }; |
| 11326 | |
| 11327 | HttpRequestInfo request; |
| 11328 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11329 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11330 | request.traffic_annotation = |
| 11331 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11332 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11333 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11334 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 11335 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11336 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11337 | ssl.ssl_info.cert = |
| 11338 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11339 | ASSERT_TRUE(ssl.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11340 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11341 | |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11342 | TestCompletionCallback callback; |
| 11343 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11344 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11345 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11346 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11347 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11348 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11349 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11350 | url::SchemeHostPort test_server("https", "www.example.org", 443); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11351 | HttpServerProperties* http_server_properties = |
| 11352 | session->http_server_properties(); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11353 | EXPECT_TRUE( |
| 11354 | http_server_properties->GetAlternativeServiceInfos(test_server).empty()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11355 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11356 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11357 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11358 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11359 | ASSERT_TRUE(response); |
| 11360 | ASSERT_TRUE(response->headers); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11361 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11362 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11363 | EXPECT_FALSE(response->was_alpn_negotiated); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11364 | |
| 11365 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11366 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11367 | EXPECT_EQ("hello world", response_data); |
| 11368 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11369 | AlternativeServiceInfoVector alternative_service_info_vector = |
| 11370 | http_server_properties->GetAlternativeServiceInfos(test_server); |
| 11371 | ASSERT_EQ(2u, alternative_service_info_vector.size()); |
| 11372 | |
| 11373 | AlternativeService alternative_service(kProtoHTTP2, "www.example.com", 443); |
| 11374 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11375 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11376 | AlternativeService alternative_service_2(kProtoHTTP2, "www.example.org", |
| 11377 | 1234); |
| 11378 | EXPECT_EQ(alternative_service_2, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11379 | alternative_service_info_vector[1].alternative_service()); |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11380 | } |
| 11381 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11382 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11383 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11384 | HostPortPair alternative("alternative.example.org", 443); |
| 11385 | std::string origin_url = "https://origin.example.org:443"; |
| 11386 | std::string alternative_url = "https://alternative.example.org:443"; |
| 11387 | |
| 11388 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 11389 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11390 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11391 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11392 | |
| 11393 | // HTTP/1.1 data for request. |
| 11394 | MockWrite http_writes[] = { |
| 11395 | MockWrite("GET / HTTP/1.1\r\n" |
| 11396 | "Host: alternative.example.org\r\n" |
| 11397 | "Connection: keep-alive\r\n\r\n"), |
| 11398 | }; |
| 11399 | |
| 11400 | MockRead http_reads[] = { |
| 11401 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11402 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11403 | "Content-Length: 40\r\n\r\n" |
| 11404 | "first HTTP/1.1 response from alternative"), |
| 11405 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11406 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11407 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11408 | |
| 11409 | StaticSocketDataProvider data_refused; |
| 11410 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 11411 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 11412 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11413 | // Set up a QUIC alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11414 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11415 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11416 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11417 | AlternativeService alternative_service(kProtoQUIC, alternative); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11418 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11419 | http_server_properties->SetQuicAlternativeService( |
| 11420 | server, alternative_service, expiration, |
| 11421 | HttpNetworkSession::Params().quic_supported_versions); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11422 | // Mark the QUIC alternative service as broken. |
| 11423 | http_server_properties->MarkAlternativeServiceBroken(alternative_service); |
| 11424 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11425 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 11426 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11427 | request.method = "GET"; |
| 11428 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11429 | request.traffic_annotation = |
| 11430 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 11431 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11432 | TestCompletionCallback callback; |
| 11433 | NetErrorDetails details; |
| 11434 | EXPECT_FALSE(details.quic_broken); |
| 11435 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11436 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11437 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11438 | EXPECT_TRUE(details.quic_broken); |
| 11439 | } |
| 11440 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11441 | TEST_F(HttpNetworkTransactionTest, IdentifyQuicNotBroken) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11442 | url::SchemeHostPort server("https", "origin.example.org", 443); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11443 | HostPortPair alternative1("alternative1.example.org", 443); |
| 11444 | HostPortPair alternative2("alternative2.example.org", 443); |
| 11445 | std::string origin_url = "https://origin.example.org:443"; |
| 11446 | std::string alternative_url1 = "https://alternative1.example.org:443"; |
| 11447 | std::string alternative_url2 = "https://alternative2.example.org:443"; |
| 11448 | |
| 11449 | // Negotiate HTTP/1.1 with alternative1.example.org. |
| 11450 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11451 | ssl.next_proto = kProtoHTTP11; |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11452 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11453 | |
| 11454 | // HTTP/1.1 data for request. |
| 11455 | MockWrite http_writes[] = { |
| 11456 | MockWrite("GET / HTTP/1.1\r\n" |
| 11457 | "Host: alternative1.example.org\r\n" |
| 11458 | "Connection: keep-alive\r\n\r\n"), |
| 11459 | }; |
| 11460 | |
| 11461 | MockRead http_reads[] = { |
| 11462 | MockRead("HTTP/1.1 200 OK\r\n" |
| 11463 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 11464 | "Content-Length: 40\r\n\r\n" |
| 11465 | "first HTTP/1.1 response from alternative1"), |
| 11466 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11467 | StaticSocketDataProvider http_data(http_reads, http_writes); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11468 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 11469 | |
| 11470 | StaticSocketDataProvider data_refused; |
| 11471 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 11472 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 11473 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11474 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11475 | HttpServerProperties* http_server_properties = |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11476 | session->http_server_properties(); |
| 11477 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11478 | // Set up two QUIC alternative services for server. |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11479 | AlternativeServiceInfoVector alternative_service_info_vector; |
| 11480 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
| 11481 | |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11482 | AlternativeService alternative_service1(kProtoQUIC, alternative1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11483 | alternative_service_info_vector.push_back( |
| 11484 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 11485 | alternative_service1, expiration, |
| 11486 | session->params().quic_supported_versions)); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11487 | AlternativeService alternative_service2(kProtoQUIC, alternative2); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11488 | alternative_service_info_vector.push_back( |
| 11489 | AlternativeServiceInfo::CreateQuicAlternativeServiceInfo( |
| 11490 | alternative_service2, expiration, |
| 11491 | session->params().quic_supported_versions)); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11492 | |
| 11493 | http_server_properties->SetAlternativeServices( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11494 | server, alternative_service_info_vector); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11495 | |
| 11496 | // Mark one of the QUIC alternative service as broken. |
| 11497 | http_server_properties->MarkAlternativeServiceBroken(alternative_service1); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11498 | EXPECT_EQ(2u, |
| 11499 | http_server_properties->GetAlternativeServiceInfos(server).size()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11500 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11501 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 11502 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11503 | request.method = "GET"; |
| 11504 | request.url = GURL(origin_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11505 | request.traffic_annotation = |
| 11506 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 11507 | |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11508 | TestCompletionCallback callback; |
| 11509 | NetErrorDetails details; |
| 11510 | EXPECT_FALSE(details.quic_broken); |
| 11511 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11512 | trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11513 | trans.PopulateNetErrorDetails(&details); |
zhongyi | 48704c18 | 2015-12-07 07:52:02 | [diff] [blame] | 11514 | EXPECT_FALSE(details.quic_broken); |
| 11515 | } |
| 11516 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11517 | TEST_F(HttpNetworkTransactionTest, MarkBrokenAlternateProtocolAndFallback) { |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11518 | HttpRequestInfo request; |
| 11519 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11520 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11521 | request.traffic_annotation = |
| 11522 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11523 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11524 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11525 | StaticSocketDataProvider first_data; |
| 11526 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11527 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11528 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11529 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11530 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11531 | |
| 11532 | MockRead data_reads[] = { |
| 11533 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11534 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11535 | MockRead(ASYNC, OK), |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11536 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11537 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11538 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11539 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11540 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11541 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11542 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11543 | session->http_server_properties(); |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11544 | const url::SchemeHostPort server(request.url); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11545 | // Port must be < 1024, or the header will be ignored (since initial port was |
| 11546 | // port 80 (another restricted port). |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11547 | // Port is ignored by MockConnect anyway. |
| 11548 | const AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11549 | 666); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11550 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11551 | http_server_properties->SetHttp2AlternativeService( |
| 11552 | server, alternative_service, expiration); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11553 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11554 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11555 | TestCompletionCallback callback; |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11556 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11557 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11558 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11559 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11560 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11561 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11562 | ASSERT_TRUE(response); |
| 11563 | ASSERT_TRUE(response->headers); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11564 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11565 | |
| 11566 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11567 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11568 | EXPECT_EQ("hello world", response_data); |
| 11569 | |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11570 | const AlternativeServiceInfoVector alternative_service_info_vector = |
| 11571 | http_server_properties->GetAlternativeServiceInfos(server); |
| 11572 | ASSERT_EQ(1u, alternative_service_info_vector.size()); |
| 11573 | EXPECT_EQ(alternative_service, |
zhongyi | 422ce35 | 2017-06-09 23:28:54 | [diff] [blame] | 11574 | alternative_service_info_vector[0].alternative_service()); |
zhongyi | c4de0303 | 2017-05-19 04:07:34 | [diff] [blame] | 11575 | EXPECT_TRUE( |
| 11576 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 11577 | } |
| 11578 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11579 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11580 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11581 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11582 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11583 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedBlocked) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11584 | HttpRequestInfo restricted_port_request; |
| 11585 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11586 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11587 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11588 | restricted_port_request.traffic_annotation = |
| 11589 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11590 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11591 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11592 | StaticSocketDataProvider first_data; |
| 11593 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11594 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11595 | |
| 11596 | MockRead data_reads[] = { |
| 11597 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11598 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11599 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11600 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11601 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11602 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11603 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11604 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11605 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11606 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11607 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11608 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11609 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11610 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11611 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11612 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11613 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11614 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11615 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11616 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11617 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11618 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11619 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11620 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11621 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11622 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 11623 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11624 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11625 | // Invalid change to unrestricted port should fail. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11626 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_REFUSED)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11627 | } |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11628 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11629 | // Ensure that we are allowed to redirect traffic via an alternate protocol to |
| 11630 | // an unrestricted (port >= 1024) when the original traffic was on a restricted |
| 11631 | // port (port < 1024) if we set |enable_user_alternate_protocol_ports|. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11632 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedPermitted) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11633 | session_deps_.enable_user_alternate_protocol_ports = true; |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11634 | |
| 11635 | HttpRequestInfo restricted_port_request; |
| 11636 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11637 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11638 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11639 | restricted_port_request.traffic_annotation = |
| 11640 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11641 | |
| 11642 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
| 11643 | StaticSocketDataProvider first_data; |
| 11644 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11645 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11646 | |
| 11647 | MockRead data_reads[] = { |
| 11648 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11649 | MockRead("hello world"), |
| 11650 | MockRead(ASYNC, OK), |
| 11651 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11652 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11653 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11654 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11655 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11656 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11657 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11658 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11659 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11660 | HttpServerProperties* http_server_properties = |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11661 | session->http_server_properties(); |
| 11662 | const int kUnrestrictedAlternatePort = 1024; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11663 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11664 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11665 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11666 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11667 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11668 | expiration); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11669 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11670 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11671 | TestCompletionCallback callback; |
| 11672 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11673 | EXPECT_EQ(ERR_IO_PENDING, |
| 11674 | trans.Start(&restricted_port_request, callback.callback(), |
| 11675 | NetLogWithSource())); |
[email protected] | c54c696 | 2013-02-01 04:53:19 | [diff] [blame] | 11676 | // Change to unrestricted port should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11677 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11678 | } |
| 11679 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11680 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11681 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11682 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11683 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11684 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortRestrictedAllowed) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11685 | HttpRequestInfo restricted_port_request; |
| 11686 | restricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11687 | restricted_port_request.url = GURL("https://www.example.org:1023/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11688 | restricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11689 | restricted_port_request.traffic_annotation = |
| 11690 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11691 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11692 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11693 | StaticSocketDataProvider first_data; |
| 11694 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11695 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11696 | |
| 11697 | MockRead data_reads[] = { |
| 11698 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11699 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11700 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11701 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11702 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11703 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11704 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11705 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11706 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11707 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11708 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11709 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11710 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11711 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11712 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11713 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11714 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11715 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11716 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11717 | url::SchemeHostPort(restricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11718 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11719 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11720 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11721 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11722 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11723 | int rv = trans.Start(&restricted_port_request, callback.callback(), |
| 11724 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11725 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11726 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11727 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11728 | } |
| 11729 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11730 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11731 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11732 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11733 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11734 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed1) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11735 | HttpRequestInfo unrestricted_port_request; |
| 11736 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11737 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11738 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11739 | unrestricted_port_request.traffic_annotation = |
| 11740 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11741 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11742 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11743 | StaticSocketDataProvider first_data; |
| 11744 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11745 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11746 | |
| 11747 | MockRead data_reads[] = { |
| 11748 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11749 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11750 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11751 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11752 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11753 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11754 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11755 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11756 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11757 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11758 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11759 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11760 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11761 | session->http_server_properties(); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11762 | const int kRestrictedAlternatePort = 80; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11763 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11764 | kRestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11765 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11766 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11767 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11768 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11769 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11770 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11771 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11772 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11773 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11774 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11775 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11776 | // Valid change to restricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11777 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11778 | } |
| 11779 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11780 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
| 11781 | // to an unrestricted (port >= 1024) when the original traffic was on a |
| 11782 | // restricted port (port < 1024). Ensure that we can redirect in all other |
| 11783 | // cases. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11784 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolPortUnrestrictedAllowed2) { |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11785 | HttpRequestInfo unrestricted_port_request; |
| 11786 | unrestricted_port_request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11787 | unrestricted_port_request.url = GURL("https://www.example.org:1024/"); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11788 | unrestricted_port_request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11789 | unrestricted_port_request.traffic_annotation = |
| 11790 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11791 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11792 | MockConnect mock_connect(ASYNC, ERR_CONNECTION_REFUSED); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11793 | StaticSocketDataProvider first_data; |
| 11794 | first_data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11795 | session_deps_.socket_factory->AddSocketDataProvider(&first_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11796 | |
| 11797 | MockRead data_reads[] = { |
| 11798 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11799 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11800 | MockRead(ASYNC, OK), |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11801 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11802 | StaticSocketDataProvider second_data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11803 | session_deps_.socket_factory->AddSocketDataProvider(&second_data); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11804 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11805 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 11806 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 11807 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11808 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11809 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11810 | HttpServerProperties* http_server_properties = |
[email protected] | 17291a02 | 2011-10-10 07:32:53 | [diff] [blame] | 11811 | session->http_server_properties(); |
bnc | 0bbb0262 | 2015-07-23 10:06:22 | [diff] [blame] | 11812 | const int kUnrestrictedAlternatePort = 1025; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11813 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11814 | kUnrestrictedAlternatePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11815 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11816 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11817 | url::SchemeHostPort(unrestricted_port_request.url), alternative_service, |
rch | dc7b905 | 2016-03-17 20:51:50 | [diff] [blame] | 11818 | expiration); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11819 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11820 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11821 | TestCompletionCallback callback; |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11822 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11823 | int rv = trans.Start(&unrestricted_port_request, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11824 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11825 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11826 | // Valid change to an unrestricted port should pass. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11827 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 3912662a3 | 2011-10-04 00:51:11 | [diff] [blame] | 11828 | } |
| 11829 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 11830 | // Ensure that we are not allowed to redirect traffic via an alternate protocol |
Xida Chen | 9bfe0b6 | 2018-04-24 19:52:21 | [diff] [blame] | 11831 | // to an unsafe port, and that we resume the second HttpStreamFactory::Job once |
| 11832 | // the alternate protocol request fails. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11833 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolUnsafeBlocked) { |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11834 | HttpRequestInfo request; |
| 11835 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 11836 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11837 | request.traffic_annotation = |
| 11838 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11839 | |
| 11840 | // The alternate protocol request will error out before we attempt to connect, |
| 11841 | // so only the standard HTTP request will try to connect. |
| 11842 | MockRead data_reads[] = { |
| 11843 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), |
| 11844 | MockRead("hello world"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 11845 | MockRead(ASYNC, OK), |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11846 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11847 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11848 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11849 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11850 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11851 | |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 11852 | HttpServerProperties* http_server_properties = |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11853 | session->http_server_properties(); |
| 11854 | const int kUnsafePort = 7; |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 11855 | AlternativeService alternative_service(kProtoHTTP2, "www.example.org", |
| 11856 | kUnsafePort); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 11857 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 11858 | http_server_properties->SetHttp2AlternativeService( |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 11859 | url::SchemeHostPort(request.url), alternative_service, expiration); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11860 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11861 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11862 | TestCompletionCallback callback; |
| 11863 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11864 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11865 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11866 | // The HTTP request should succeed. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11867 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11868 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11869 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11870 | ASSERT_TRUE(response); |
| 11871 | ASSERT_TRUE(response->headers); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11872 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11873 | |
| 11874 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 11875 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | eb6234e | 2012-01-19 01:50:02 | [diff] [blame] | 11876 | EXPECT_EQ("hello world", response_data); |
| 11877 | } |
| 11878 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11879 | TEST_F(HttpNetworkTransactionTest, UseAlternateProtocolForNpnSpdy) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11880 | HttpRequestInfo request; |
| 11881 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11882 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11883 | request.traffic_annotation = |
| 11884 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11885 | |
| 11886 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11887 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11888 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11889 | MockRead("\r\n"), |
| 11890 | MockRead("hello world"), |
| 11891 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11892 | MockRead(ASYNC, OK)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11893 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11894 | StaticSocketDataProvider first_transaction(data_reads, |
| 11895 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11896 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11897 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 11898 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11899 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11900 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 11901 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11902 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11903 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11904 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11905 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11906 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 11907 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 11908 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11909 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 11910 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11911 | }; |
| 11912 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11913 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11914 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11915 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11916 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11917 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11918 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 11919 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 11920 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11921 | &hanging_non_alternate_protocol_socket); |
| 11922 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 11923 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11924 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 11925 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11926 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11927 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11928 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11929 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11930 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11931 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11932 | |
| 11933 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11934 | ASSERT_TRUE(response); |
| 11935 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11936 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 11937 | |
| 11938 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11939 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11940 | EXPECT_EQ("hello world", response_data); |
| 11941 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 11942 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 11943 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11944 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 11945 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11946 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 11947 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11948 | |
| 11949 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 11950 | ASSERT_TRUE(response); |
| 11951 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 11952 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 11953 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 11954 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11955 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 11956 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11957 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 11958 | } |
| 11959 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 11960 | TEST_F(HttpNetworkTransactionTest, AlternateProtocolWithSpdyLateBinding) { |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11961 | HttpRequestInfo request; |
| 11962 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11963 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 11964 | request.traffic_annotation = |
| 11965 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11966 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11967 | // First transaction receives Alt-Svc header over HTTP/1.1. |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11968 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11969 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 11970 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 11971 | MockRead("\r\n"), |
| 11972 | MockRead("hello world"), |
| 11973 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 11974 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11975 | }; |
| 11976 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11977 | StaticSocketDataProvider http11_data(data_reads, base::span<MockWrite>()); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11978 | session_deps_.socket_factory->AddSocketDataProvider(&http11_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11979 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11980 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 11981 | ssl_http11.ssl_info.cert = |
| 11982 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 11983 | ASSERT_TRUE(ssl_http11.ssl_info.cert); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11984 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
| 11985 | |
| 11986 | // Second transaction starts an alternative and a non-alternative Job. |
| 11987 | // Both sockets hang. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 11988 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11989 | StaticSocketDataProvider hanging_socket1; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11990 | hanging_socket1.set_connect_data(never_finishing_connect); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11991 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket1); |
| 11992 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 11993 | StaticSocketDataProvider hanging_socket2; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 11994 | hanging_socket2.set_connect_data(never_finishing_connect); |
| 11995 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket2); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 11996 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 11997 | // Third transaction starts an alternative and a non-alternative job. |
| 11998 | // The non-alternative job hangs, but the alternative one succeeds. |
| 11999 | // The second transaction, still pending, binds to this socket. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12000 | spdy::SpdySerializedFrame req1( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12001 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12002 | spdy::SpdySerializedFrame req2( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12003 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 3, LOWEST)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12004 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12005 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 1), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12006 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12007 | spdy::SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 12008 | spdy::SpdySerializedFrame data1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 12009 | spdy::SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 12010 | spdy::SpdySerializedFrame data2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12011 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12012 | CreateMockRead(resp1, 2), CreateMockRead(data1, 3), |
| 12013 | CreateMockRead(resp2, 4), CreateMockRead(data2, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12014 | MockRead(ASYNC, 0, 6), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12015 | }; |
| 12016 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12017 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12018 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12019 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12020 | AddSSLSocketData(); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12021 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12022 | StaticSocketDataProvider hanging_socket3; |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12023 | hanging_socket3.set_connect_data(never_finishing_connect); |
| 12024 | session_deps_.socket_factory->AddSocketDataProvider(&hanging_socket3); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12025 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12026 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12027 | TestCompletionCallback callback1; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12028 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12029 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12030 | int rv = trans1.Start(&request, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12031 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12032 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12033 | |
| 12034 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12035 | ASSERT_TRUE(response); |
| 12036 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12037 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12038 | |
| 12039 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12040 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12041 | EXPECT_EQ("hello world", response_data); |
| 12042 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12043 | TestCompletionCallback callback2; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12044 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12045 | rv = trans2.Start(&request, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12046 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12047 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12048 | TestCompletionCallback callback3; |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 12049 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12050 | rv = trans3.Start(&request, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12051 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12052 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12053 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
| 12054 | EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12055 | |
| 12056 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12057 | ASSERT_TRUE(response); |
| 12058 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12059 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12060 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12061 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12062 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12063 | EXPECT_EQ("hello!", response_data); |
| 12064 | |
| 12065 | response = trans3.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12066 | ASSERT_TRUE(response); |
| 12067 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12068 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12069 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12070 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12071 | ASSERT_THAT(ReadTransaction(&trans3, &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12072 | EXPECT_EQ("hello!", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12073 | } |
| 12074 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12075 | TEST_F(HttpNetworkTransactionTest, StallAlternativeServiceForNpnSpdy) { |
Bence Béky | bcae3709 | 2018-06-12 04:18:53 | [diff] [blame] | 12076 | session_deps_.host_resolver->set_synchronous_mode(true); |
| 12077 | |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12078 | HttpRequestInfo request; |
| 12079 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12080 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12081 | request.traffic_annotation = |
| 12082 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12083 | |
| 12084 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12085 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12086 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12087 | MockRead("\r\n"), |
| 12088 | MockRead("hello world"), |
| 12089 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12090 | MockRead(ASYNC, OK), |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12091 | }; |
| 12092 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12093 | StaticSocketDataProvider first_transaction(data_reads, |
| 12094 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12095 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12096 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 12097 | SSLSocketDataProvider ssl(ASYNC, OK); |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 12098 | ssl.ssl_info.cert = |
| 12099 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 12100 | ASSERT_TRUE(ssl.ssl_info.cert); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12101 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12102 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12103 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12104 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12105 | hanging_alternate_protocol_socket.set_connect_data( |
| 12106 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12107 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12108 | &hanging_alternate_protocol_socket); |
| 12109 | |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12110 | // 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] | 12111 | StaticSocketDataProvider second_transaction(data_reads, |
| 12112 | base::span<MockWrite>()); |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 12113 | session_deps_.socket_factory->AddSocketDataProvider(&second_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12114 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12115 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12116 | TestCompletionCallback callback; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12117 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12118 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12119 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12120 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12121 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12122 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12123 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12124 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12125 | |
| 12126 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12127 | ASSERT_TRUE(response); |
| 12128 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12129 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12130 | |
| 12131 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12132 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12133 | EXPECT_EQ("hello world", response_data); |
| 12134 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12135 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12136 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12137 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12138 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12139 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12140 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12141 | |
| 12142 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12143 | ASSERT_TRUE(response); |
| 12144 | ASSERT_TRUE(response->headers); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12145 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12146 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12147 | EXPECT_FALSE(response->was_alpn_negotiated); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12148 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12149 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12150 | EXPECT_EQ("hello world", response_data); |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12151 | } |
| 12152 | |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12153 | class CapturingProxyResolver : public ProxyResolver { |
| 12154 | public: |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 12155 | CapturingProxyResolver() = default; |
| 12156 | ~CapturingProxyResolver() override = default; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12157 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 12158 | int GetProxyForURL(const GURL& url, |
| 12159 | ProxyInfo* results, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 12160 | CompletionOnceCallback callback, |
maksim.sisov | 7e15726 | 2016-10-20 11:19:55 | [diff] [blame] | 12161 | std::unique_ptr<Request>* request, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12162 | const NetLogWithSource& net_log) override { |
[email protected] | fae7669f | 2010-08-02 21:49:40 | [diff] [blame] | 12163 | ProxyServer proxy_server(ProxyServer::SCHEME_HTTP, |
| 12164 | HostPortPair("myproxy", 80)); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12165 | results->UseProxyServer(proxy_server); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12166 | resolved_.push_back(url); |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12167 | return OK; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12168 | } |
| 12169 | |
[email protected] | 2447640 | 2010-07-20 20:55:17 | [diff] [blame] | 12170 | const std::vector<GURL>& resolved() const { return resolved_; } |
| 12171 | |
| 12172 | private: |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12173 | std::vector<GURL> resolved_; |
| 12174 | |
| 12175 | DISALLOW_COPY_AND_ASSIGN(CapturingProxyResolver); |
| 12176 | }; |
| 12177 | |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 12178 | class CapturingProxyResolverFactory : public ProxyResolverFactory { |
| 12179 | public: |
| 12180 | explicit CapturingProxyResolverFactory(CapturingProxyResolver* resolver) |
| 12181 | : ProxyResolverFactory(false), resolver_(resolver) {} |
| 12182 | |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 12183 | int CreateProxyResolver(const scoped_refptr<PacFileData>& pac_script, |
| 12184 | std::unique_ptr<ProxyResolver>* resolver, |
Bence Béky | cc5b88a | 2018-05-25 20:24:17 | [diff] [blame] | 12185 | CompletionOnceCallback callback, |
Lily Houghton | 9959786 | 2018-03-07 16:40:42 | [diff] [blame] | 12186 | std::unique_ptr<Request>* request) override { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12187 | *resolver = std::make_unique<ForwardingProxyResolver>(resolver_); |
sammc | e64b236 | 2015-04-29 03:50:23 | [diff] [blame] | 12188 | return OK; |
| 12189 | } |
| 12190 | |
| 12191 | private: |
| 12192 | ProxyResolver* resolver_; |
| 12193 | }; |
| 12194 | |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12195 | // Test that proxy is resolved using the origin url, |
| 12196 | // regardless of the alternative server. |
| 12197 | TEST_F(HttpNetworkTransactionTest, UseOriginNotAlternativeForProxy) { |
| 12198 | // Configure proxy to bypass www.example.org, which is the origin URL. |
| 12199 | ProxyConfig proxy_config; |
| 12200 | proxy_config.proxy_rules().ParseFromString("myproxy:70"); |
| 12201 | proxy_config.proxy_rules().bypass_rules.AddRuleFromString("www.example.org"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 12202 | auto proxy_config_service = std::make_unique<ProxyConfigServiceFixed>( |
| 12203 | ProxyConfigWithAnnotation(proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12204 | |
| 12205 | CapturingProxyResolver capturing_proxy_resolver; |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12206 | auto proxy_resolver_factory = std::make_unique<CapturingProxyResolverFactory>( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12207 | &capturing_proxy_resolver); |
| 12208 | |
| 12209 | TestNetLog net_log; |
| 12210 | |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 12211 | session_deps_.proxy_resolution_service = |
| 12212 | std::make_unique<ProxyResolutionService>( |
| 12213 | std::move(proxy_config_service), std::move(proxy_resolver_factory), |
| 12214 | &net_log); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12215 | |
| 12216 | session_deps_.net_log = &net_log; |
| 12217 | |
| 12218 | // Configure alternative service with a hostname that is not bypassed by the |
| 12219 | // proxy. |
| 12220 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 12221 | HttpServerProperties* http_server_properties = |
| 12222 | session->http_server_properties(); |
| 12223 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 12224 | HostPortPair alternative("www.example.com", 443); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 12225 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12226 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 12227 | http_server_properties->SetHttp2AlternativeService( |
| 12228 | server, alternative_service, expiration); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12229 | |
| 12230 | // Non-alternative job should hang. |
| 12231 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12232 | StaticSocketDataProvider hanging_alternate_protocol_socket; |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12233 | hanging_alternate_protocol_socket.set_connect_data(never_finishing_connect); |
| 12234 | session_deps_.socket_factory->AddSocketDataProvider( |
| 12235 | &hanging_alternate_protocol_socket); |
| 12236 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12237 | AddSSLSocketData(); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12238 | |
| 12239 | HttpRequestInfo request; |
| 12240 | request.method = "GET"; |
| 12241 | request.url = GURL("https://www.example.org/"); |
| 12242 | request.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12243 | request.traffic_annotation = |
| 12244 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12245 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12246 | spdy::SpdySerializedFrame req( |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12247 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
| 12248 | |
| 12249 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
| 12250 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12251 | spdy::SpdySerializedFrame resp( |
| 12252 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 12253 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12254 | MockRead spdy_reads[] = { |
| 12255 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
| 12256 | }; |
| 12257 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12258 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12259 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
| 12260 | |
| 12261 | TestCompletionCallback callback; |
| 12262 | |
| 12263 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 12264 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12265 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12266 | EXPECT_THAT(callback.GetResult(rv), IsOk()); |
| 12267 | |
| 12268 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
| 12269 | ASSERT_TRUE(response); |
| 12270 | ASSERT_TRUE(response->headers); |
| 12271 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 12272 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12273 | EXPECT_TRUE(response->was_alpn_negotiated); |
bnc | 2e88478 | 2016-08-11 19:45:19 | [diff] [blame] | 12274 | |
| 12275 | std::string response_data; |
| 12276 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
| 12277 | EXPECT_EQ("hello!", response_data); |
| 12278 | |
| 12279 | // Origin host bypasses proxy, no resolution should have happened. |
| 12280 | ASSERT_TRUE(capturing_proxy_resolver.resolved().empty()); |
| 12281 | } |
| 12282 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12283 | TEST_F(HttpNetworkTransactionTest, UseAlternativeServiceForTunneledNpnSpdy) { |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12284 | ProxyConfig proxy_config; |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12285 | proxy_config.set_auto_detect(true); |
| 12286 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
[email protected] | 2227c69 | 2010-05-04 15:36:11 | [diff] [blame] | 12287 | |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12288 | CapturingProxyResolver capturing_proxy_resolver; |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 12289 | session_deps_.proxy_resolution_service = |
| 12290 | std::make_unique<ProxyResolutionService>( |
| 12291 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 12292 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 12293 | std::make_unique<CapturingProxyResolverFactory>( |
| 12294 | &capturing_proxy_resolver), |
| 12295 | nullptr); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 12296 | TestNetLog net_log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12297 | session_deps_.net_log = &net_log; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12298 | |
| 12299 | HttpRequestInfo request; |
| 12300 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12301 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12302 | request.traffic_annotation = |
| 12303 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12304 | |
| 12305 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12306 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12307 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12308 | MockRead("\r\n"), |
| 12309 | MockRead("hello world"), |
| 12310 | MockRead(SYNCHRONOUS, ERR_TEST_PEER_CLOSE_AFTER_NEXT_MOCK_READ), |
| 12311 | MockRead(ASYNC, OK), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12312 | }; |
| 12313 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12314 | StaticSocketDataProvider first_transaction(data_reads, |
| 12315 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12316 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12317 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12318 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12319 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12320 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12321 | AddSSLSocketData(); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12322 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12323 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12324 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12325 | MockWrite spdy_writes[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12326 | MockWrite(ASYNC, 0, |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12327 | "CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 12328 | "Host: www.example.org:443\r\n" |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 12329 | "Proxy-Connection: keep-alive\r\n\r\n"), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12330 | CreateMockWrite(req, 2), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12331 | }; |
| 12332 | |
[email protected] | d911f1b | 2010-05-05 22:39:42 | [diff] [blame] | 12333 | const char kCONNECTResponse[] = "HTTP/1.1 200 Connected\r\n\r\n"; |
| 12334 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12335 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 12336 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12337 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12338 | MockRead(ASYNC, 1, kCONNECTResponse), CreateMockRead(resp, 3), |
| 12339 | CreateMockRead(data, 4), MockRead(SYNCHRONOUS, ERR_IO_PENDING, 5), |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12340 | }; |
| 12341 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12342 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12343 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12344 | |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 12345 | MockConnect never_finishing_connect(SYNCHRONOUS, ERR_IO_PENDING); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12346 | StaticSocketDataProvider hanging_non_alternate_protocol_socket; |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12347 | hanging_non_alternate_protocol_socket.set_connect_data( |
| 12348 | never_finishing_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12349 | session_deps_.socket_factory->AddSocketDataProvider( |
[email protected] | 2d672869 | 2011-03-12 01:39:55 | [diff] [blame] | 12350 | &hanging_non_alternate_protocol_socket); |
| 12351 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 12352 | TestCompletionCallback callback; |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12353 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12354 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12355 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12356 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12357 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12358 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12359 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12360 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 12361 | |
| 12362 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 12363 | ASSERT_TRUE(response); |
| 12364 | ASSERT_TRUE(response->headers); |
| 12365 | EXPECT_EQ("HTTP/0.9 200 OK", response->headers->GetStatusLine()); |
| 12366 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12367 | EXPECT_TRUE(response->was_alpn_negotiated); |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12368 | |
| 12369 | std::string response_data; |
| 12370 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
| 12371 | EXPECT_EQ("hello world", response_data); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12372 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12373 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12374 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12375 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12376 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12377 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12378 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12379 | |
mmenke | a2dcd3bf | 2016-08-16 21:49:41 | [diff] [blame] | 12380 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12381 | ASSERT_TRUE(response); |
| 12382 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12383 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12384 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12385 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12386 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12387 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12388 | EXPECT_EQ("hello!", response_data); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12389 | ASSERT_EQ(2u, capturing_proxy_resolver.resolved().size()); |
| 12390 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12391 | capturing_proxy_resolver.resolved()[0].spec()); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 12392 | EXPECT_EQ("https://www.example.org/", |
sammc | 5dd160c | 2015-04-02 02:43:13 | [diff] [blame] | 12393 | capturing_proxy_resolver.resolved()[1].spec()); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12394 | |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 12395 | LoadTimingInfo load_timing_info; |
| 12396 | EXPECT_TRUE(trans->GetLoadTimingInfo(&load_timing_info)); |
| 12397 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 12398 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12399 | } |
[email protected] | 631f132 | 2010-04-30 17:59:11 | [diff] [blame] | 12400 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12401 | TEST_F(HttpNetworkTransactionTest, |
bnc | 1c196c6e | 2016-05-28 13:51:48 | [diff] [blame] | 12402 | UseAlternativeServiceForNpnSpdyWithExistingSpdySession) { |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12403 | HttpRequestInfo request; |
| 12404 | request.method = "GET"; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12405 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 12406 | request.traffic_annotation = |
| 12407 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12408 | |
| 12409 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12410 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 12411 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 12412 | MockRead("\r\n"), |
| 12413 | MockRead("hello world"), |
| 12414 | MockRead(ASYNC, OK), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12415 | }; |
| 12416 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12417 | StaticSocketDataProvider first_transaction(data_reads, |
| 12418 | base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12419 | session_deps_.socket_factory->AddSocketDataProvider(&first_transaction); |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12420 | SSLSocketDataProvider ssl_http11(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 12421 | ssl_http11.next_proto = kProtoHTTP11; |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12422 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_http11); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12423 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 12424 | AddSSLSocketData(); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12425 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12426 | spdy::SpdySerializedFrame req( |
bnc | b2602438 | 2016-06-29 02:39:45 | [diff] [blame] | 12427 | spdy_util_.ConstructSpdyGet("https://www.example.org/", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12428 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12429 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 12430 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 12431 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12432 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 12433 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12434 | }; |
| 12435 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 12436 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 12437 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12438 | |
[email protected] | 83039bb | 2011-12-09 18:43:55 | [diff] [blame] | 12439 | TestCompletionCallback callback; |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12440 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 12441 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12442 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12443 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12444 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12445 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12446 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12447 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12448 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12449 | |
| 12450 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12451 | ASSERT_TRUE(response); |
| 12452 | ASSERT_TRUE(response->headers); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12453 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 12454 | |
| 12455 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12456 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12457 | EXPECT_EQ("hello world", response_data); |
| 12458 | |
| 12459 | // Set up an initial SpdySession in the pool to reuse. |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 12460 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 12461 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 12462 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 12463 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 12464 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 02b0c34 | 2010-09-25 21:09:38 | [diff] [blame] | 12465 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 12466 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 12467 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12468 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 12469 | rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12470 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 12471 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12472 | |
| 12473 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 12474 | ASSERT_TRUE(response); |
| 12475 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 12476 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 12477 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 12478 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12479 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 12480 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 2ff8b31 | 2010-04-26 22:20:54 | [diff] [blame] | 12481 | EXPECT_EQ("hello!", response_data); |
[email protected] | 564b491 | 2010-03-09 16:30:42 | [diff] [blame] | 12482 | } |
| 12483 | |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12484 | // GenerateAuthToken is a mighty big test. |
| 12485 | // It tests all permutation of GenerateAuthToken behavior: |
| 12486 | // - Synchronous and Asynchronous completion. |
| 12487 | // - OK or error on completion. |
| 12488 | // - Direct connection, non-authenticating proxy, and authenticating proxy. |
| 12489 | // - HTTP or HTTPS backend (to include proxy tunneling). |
| 12490 | // - Non-authenticating and authenticating backend. |
| 12491 | // |
[email protected] | fe3b7dc | 2012-02-03 19:52:09 | [diff] [blame] | 12492 | // In all, there are 44 reasonable permuations (for example, if there are |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12493 | // problems generating an auth token for an authenticating proxy, we don't |
| 12494 | // need to test all permutations of the backend server). |
| 12495 | // |
| 12496 | // The test proceeds by going over each of the configuration cases, and |
| 12497 | // potentially running up to three rounds in each of the tests. The TestConfig |
| 12498 | // specifies both the configuration for the test as well as the expectations |
| 12499 | // for the results. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 12500 | TEST_F(HttpNetworkTransactionTest, GenerateAuthToken) { |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 12501 | static const char kServer[] = "http://www.example.com"; |
| 12502 | static const char kSecureServer[] = "https://www.example.com"; |
| 12503 | static const char kProxy[] = "myproxy:70"; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12504 | |
| 12505 | enum AuthTiming { |
| 12506 | AUTH_NONE, |
| 12507 | AUTH_SYNC, |
| 12508 | AUTH_ASYNC, |
| 12509 | }; |
| 12510 | |
| 12511 | const MockWrite kGet( |
| 12512 | "GET / HTTP/1.1\r\n" |
| 12513 | "Host: www.example.com\r\n" |
| 12514 | "Connection: keep-alive\r\n\r\n"); |
| 12515 | const MockWrite kGetProxy( |
| 12516 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12517 | "Host: www.example.com\r\n" |
| 12518 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 12519 | const MockWrite kGetAuth( |
| 12520 | "GET / HTTP/1.1\r\n" |
| 12521 | "Host: www.example.com\r\n" |
| 12522 | "Connection: keep-alive\r\n" |
| 12523 | "Authorization: auth_token\r\n\r\n"); |
| 12524 | const MockWrite kGetProxyAuth( |
| 12525 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12526 | "Host: www.example.com\r\n" |
| 12527 | "Proxy-Connection: keep-alive\r\n" |
| 12528 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 12529 | const MockWrite kGetAuthThroughProxy( |
| 12530 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12531 | "Host: www.example.com\r\n" |
| 12532 | "Proxy-Connection: keep-alive\r\n" |
| 12533 | "Authorization: auth_token\r\n\r\n"); |
| 12534 | const MockWrite kGetAuthWithProxyAuth( |
| 12535 | "GET http://www.example.com/ HTTP/1.1\r\n" |
| 12536 | "Host: www.example.com\r\n" |
| 12537 | "Proxy-Connection: keep-alive\r\n" |
| 12538 | "Proxy-Authorization: auth_token\r\n" |
| 12539 | "Authorization: auth_token\r\n\r\n"); |
| 12540 | const MockWrite kConnect( |
| 12541 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12542 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12543 | "Proxy-Connection: keep-alive\r\n\r\n"); |
| 12544 | const MockWrite kConnectProxyAuth( |
| 12545 | "CONNECT www.example.com:443 HTTP/1.1\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 12546 | "Host: www.example.com:443\r\n" |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12547 | "Proxy-Connection: keep-alive\r\n" |
| 12548 | "Proxy-Authorization: auth_token\r\n\r\n"); |
| 12549 | |
| 12550 | const MockRead kSuccess( |
| 12551 | "HTTP/1.1 200 OK\r\n" |
| 12552 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12553 | "Content-Length: 3\r\n\r\n" |
| 12554 | "Yes"); |
| 12555 | const MockRead kFailure( |
| 12556 | "Should not be called."); |
| 12557 | const MockRead kServerChallenge( |
| 12558 | "HTTP/1.1 401 Unauthorized\r\n" |
| 12559 | "WWW-Authenticate: Mock realm=server\r\n" |
| 12560 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12561 | "Content-Length: 14\r\n\r\n" |
| 12562 | "Unauthorized\r\n"); |
| 12563 | const MockRead kProxyChallenge( |
| 12564 | "HTTP/1.1 407 Unauthorized\r\n" |
| 12565 | "Proxy-Authenticate: Mock realm=proxy\r\n" |
| 12566 | "Proxy-Connection: close\r\n" |
| 12567 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 12568 | "Content-Length: 14\r\n\r\n" |
| 12569 | "Unauthorized\r\n"); |
| 12570 | const MockRead kProxyConnected( |
| 12571 | "HTTP/1.1 200 Connection Established\r\n\r\n"); |
| 12572 | |
| 12573 | // NOTE(cbentzel): I wanted TestReadWriteRound to be a simple struct with |
| 12574 | // no constructors, but the C++ compiler on Windows warns about |
| 12575 | // unspecified data in compound literals. So, moved to using constructors, |
| 12576 | // and TestRound's created with the default constructor should not be used. |
| 12577 | struct TestRound { |
| 12578 | TestRound() |
| 12579 | : expected_rv(ERR_UNEXPECTED), |
| 12580 | extra_write(NULL), |
| 12581 | extra_read(NULL) { |
| 12582 | } |
| 12583 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 12584 | int expected_rv_arg) |
| 12585 | : write(write_arg), |
| 12586 | read(read_arg), |
| 12587 | expected_rv(expected_rv_arg), |
| 12588 | extra_write(NULL), |
| 12589 | extra_read(NULL) { |
| 12590 | } |
| 12591 | TestRound(const MockWrite& write_arg, const MockRead& read_arg, |
| 12592 | int expected_rv_arg, const MockWrite* extra_write_arg, |
[email protected] | f871ee15 | 2012-07-27 19:02:01 | [diff] [blame] | 12593 | const MockRead* extra_read_arg) |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12594 | : write(write_arg), |
| 12595 | read(read_arg), |
| 12596 | expected_rv(expected_rv_arg), |
| 12597 | extra_write(extra_write_arg), |
| 12598 | extra_read(extra_read_arg) { |
| 12599 | } |
| 12600 | MockWrite write; |
| 12601 | MockRead read; |
| 12602 | int expected_rv; |
| 12603 | const MockWrite* extra_write; |
| 12604 | const MockRead* extra_read; |
| 12605 | }; |
| 12606 | |
| 12607 | static const int kNoSSL = 500; |
| 12608 | |
| 12609 | struct TestConfig { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12610 | int line_number; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12611 | const char* const proxy_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12612 | AuthTiming proxy_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12613 | int first_generate_proxy_token_rv; |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 12614 | const char* const server_url; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12615 | AuthTiming server_auth_timing; |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12616 | int first_generate_server_token_rv; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12617 | int num_auth_rounds; |
| 12618 | int first_ssl_round; |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12619 | TestRound rounds[4]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12620 | } test_configs[] = { |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12621 | // Non-authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12622 | {__LINE__, |
| 12623 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12624 | AUTH_NONE, |
| 12625 | OK, |
| 12626 | kServer, |
| 12627 | AUTH_NONE, |
| 12628 | OK, |
| 12629 | 1, |
| 12630 | kNoSSL, |
| 12631 | {TestRound(kGet, kSuccess, OK)}}, |
| 12632 | // Authenticating HTTP server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12633 | {__LINE__, |
| 12634 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12635 | AUTH_NONE, |
| 12636 | OK, |
| 12637 | kServer, |
| 12638 | AUTH_SYNC, |
| 12639 | OK, |
| 12640 | 2, |
| 12641 | kNoSSL, |
| 12642 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12643 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12644 | {__LINE__, |
| 12645 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12646 | AUTH_NONE, |
| 12647 | OK, |
| 12648 | kServer, |
| 12649 | AUTH_SYNC, |
| 12650 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12651 | 3, |
| 12652 | kNoSSL, |
| 12653 | {TestRound(kGet, kServerChallenge, OK), |
| 12654 | TestRound(kGet, kServerChallenge, OK), |
| 12655 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12656 | {__LINE__, |
| 12657 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12658 | AUTH_NONE, |
| 12659 | OK, |
| 12660 | kServer, |
| 12661 | AUTH_SYNC, |
| 12662 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 12663 | 2, |
| 12664 | kNoSSL, |
| 12665 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12666 | {__LINE__, |
| 12667 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12668 | AUTH_NONE, |
| 12669 | OK, |
| 12670 | kServer, |
| 12671 | AUTH_SYNC, |
| 12672 | ERR_UNDOCUMENTED_SECURITY_LIBRARY_STATUS, |
| 12673 | 2, |
| 12674 | kNoSSL, |
| 12675 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12676 | {__LINE__, |
| 12677 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12678 | AUTH_SYNC, |
| 12679 | ERR_FAILED, |
| 12680 | kServer, |
| 12681 | AUTH_NONE, |
| 12682 | OK, |
| 12683 | 2, |
| 12684 | kNoSSL, |
| 12685 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12686 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12687 | {__LINE__, |
| 12688 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12689 | AUTH_ASYNC, |
| 12690 | ERR_FAILED, |
| 12691 | kServer, |
| 12692 | AUTH_NONE, |
| 12693 | OK, |
| 12694 | 2, |
| 12695 | kNoSSL, |
| 12696 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12697 | TestRound(kGetProxy, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12698 | {__LINE__, |
| 12699 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12700 | AUTH_NONE, |
| 12701 | OK, |
| 12702 | kServer, |
| 12703 | AUTH_SYNC, |
| 12704 | ERR_FAILED, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12705 | 2, |
| 12706 | kNoSSL, |
| 12707 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12708 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12709 | {__LINE__, |
| 12710 | nullptr, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12711 | AUTH_NONE, |
| 12712 | OK, |
| 12713 | kServer, |
| 12714 | AUTH_ASYNC, |
| 12715 | ERR_FAILED, |
| 12716 | 2, |
| 12717 | kNoSSL, |
| 12718 | {TestRound(kGet, kServerChallenge, OK), |
| 12719 | TestRound(kGet, kFailure, ERR_FAILED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12720 | {__LINE__, |
| 12721 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12722 | AUTH_NONE, |
| 12723 | OK, |
| 12724 | kServer, |
| 12725 | AUTH_ASYNC, |
| 12726 | OK, |
| 12727 | 2, |
| 12728 | kNoSSL, |
| 12729 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12730 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12731 | {__LINE__, |
| 12732 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12733 | AUTH_NONE, |
| 12734 | OK, |
| 12735 | kServer, |
| 12736 | AUTH_ASYNC, |
| 12737 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12738 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12739 | kNoSSL, |
| 12740 | {TestRound(kGet, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12741 | // The second round uses a HttpAuthHandlerMock that always succeeds. |
| 12742 | TestRound(kGet, kServerChallenge, OK), |
| 12743 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12744 | // Non-authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12745 | {__LINE__, |
| 12746 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12747 | AUTH_NONE, |
| 12748 | OK, |
| 12749 | kServer, |
| 12750 | AUTH_NONE, |
| 12751 | OK, |
| 12752 | 1, |
| 12753 | kNoSSL, |
| 12754 | {TestRound(kGetProxy, kSuccess, OK)}}, |
| 12755 | // Authenticating HTTP server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12756 | {__LINE__, |
| 12757 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12758 | AUTH_NONE, |
| 12759 | OK, |
| 12760 | kServer, |
| 12761 | AUTH_SYNC, |
| 12762 | OK, |
| 12763 | 2, |
| 12764 | kNoSSL, |
| 12765 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12766 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12767 | {__LINE__, |
| 12768 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12769 | AUTH_NONE, |
| 12770 | OK, |
| 12771 | kServer, |
| 12772 | AUTH_SYNC, |
| 12773 | ERR_INVALID_AUTH_CREDENTIALS, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12774 | 3, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12775 | kNoSSL, |
| 12776 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12777 | TestRound(kGetProxy, kServerChallenge, OK), |
| 12778 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12779 | {__LINE__, |
| 12780 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12781 | AUTH_NONE, |
| 12782 | OK, |
| 12783 | kServer, |
| 12784 | AUTH_ASYNC, |
| 12785 | OK, |
| 12786 | 2, |
| 12787 | kNoSSL, |
| 12788 | {TestRound(kGetProxy, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12789 | TestRound(kGetAuthThroughProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12790 | {__LINE__, |
| 12791 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12792 | AUTH_NONE, |
| 12793 | OK, |
| 12794 | kServer, |
| 12795 | AUTH_ASYNC, |
| 12796 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12797 | 2, |
| 12798 | kNoSSL, |
| 12799 | {TestRound(kGetProxy, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12800 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12801 | // Non-authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12802 | {__LINE__, |
| 12803 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12804 | AUTH_SYNC, |
| 12805 | OK, |
| 12806 | kServer, |
| 12807 | AUTH_NONE, |
| 12808 | OK, |
| 12809 | 2, |
| 12810 | kNoSSL, |
| 12811 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12812 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12813 | {__LINE__, |
| 12814 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12815 | AUTH_SYNC, |
| 12816 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12817 | kServer, |
| 12818 | AUTH_NONE, |
| 12819 | OK, |
| 12820 | 2, |
| 12821 | kNoSSL, |
| 12822 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12823 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12824 | {__LINE__, |
| 12825 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12826 | AUTH_ASYNC, |
| 12827 | OK, |
| 12828 | kServer, |
| 12829 | AUTH_NONE, |
| 12830 | OK, |
| 12831 | 2, |
| 12832 | kNoSSL, |
| 12833 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12834 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12835 | {__LINE__, |
| 12836 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12837 | AUTH_ASYNC, |
| 12838 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12839 | kServer, |
| 12840 | AUTH_NONE, |
| 12841 | OK, |
| 12842 | 2, |
| 12843 | kNoSSL, |
| 12844 | {TestRound(kGetProxy, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12845 | TestRound(kGetProxy, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12846 | {__LINE__, |
| 12847 | kProxy, |
| 12848 | AUTH_ASYNC, |
| 12849 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12850 | kServer, |
| 12851 | AUTH_NONE, |
| 12852 | OK, |
| 12853 | 3, |
| 12854 | kNoSSL, |
| 12855 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12856 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12857 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12858 | // Authenticating HTTP server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12859 | {__LINE__, |
| 12860 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12861 | AUTH_SYNC, |
| 12862 | OK, |
| 12863 | kServer, |
| 12864 | AUTH_SYNC, |
| 12865 | OK, |
| 12866 | 3, |
| 12867 | kNoSSL, |
| 12868 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12869 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12870 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12871 | {__LINE__, |
| 12872 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12873 | AUTH_SYNC, |
| 12874 | OK, |
| 12875 | kServer, |
| 12876 | AUTH_SYNC, |
| 12877 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12878 | 3, |
| 12879 | kNoSSL, |
| 12880 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12881 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12882 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12883 | {__LINE__, |
| 12884 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12885 | AUTH_ASYNC, |
| 12886 | OK, |
| 12887 | kServer, |
| 12888 | AUTH_SYNC, |
| 12889 | OK, |
| 12890 | 3, |
| 12891 | kNoSSL, |
| 12892 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12893 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12894 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12895 | {__LINE__, |
| 12896 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12897 | AUTH_ASYNC, |
| 12898 | OK, |
| 12899 | kServer, |
| 12900 | AUTH_SYNC, |
| 12901 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12902 | 3, |
| 12903 | kNoSSL, |
| 12904 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12905 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12906 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12907 | {__LINE__, |
| 12908 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12909 | AUTH_SYNC, |
| 12910 | OK, |
| 12911 | kServer, |
| 12912 | AUTH_ASYNC, |
| 12913 | OK, |
| 12914 | 3, |
| 12915 | kNoSSL, |
| 12916 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12917 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12918 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12919 | {__LINE__, |
| 12920 | kProxy, |
| 12921 | AUTH_SYNC, |
| 12922 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12923 | kServer, |
| 12924 | AUTH_ASYNC, |
| 12925 | OK, |
| 12926 | 4, |
| 12927 | kNoSSL, |
| 12928 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12929 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12930 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12931 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
| 12932 | {__LINE__, |
| 12933 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12934 | AUTH_SYNC, |
| 12935 | OK, |
| 12936 | kServer, |
| 12937 | AUTH_ASYNC, |
| 12938 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12939 | 3, |
| 12940 | kNoSSL, |
| 12941 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12942 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12943 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12944 | {__LINE__, |
| 12945 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12946 | AUTH_ASYNC, |
| 12947 | OK, |
| 12948 | kServer, |
| 12949 | AUTH_ASYNC, |
| 12950 | OK, |
| 12951 | 3, |
| 12952 | kNoSSL, |
| 12953 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12954 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12955 | TestRound(kGetAuthWithProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12956 | {__LINE__, |
| 12957 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12958 | AUTH_ASYNC, |
| 12959 | OK, |
| 12960 | kServer, |
| 12961 | AUTH_ASYNC, |
| 12962 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12963 | 3, |
| 12964 | kNoSSL, |
| 12965 | {TestRound(kGetProxy, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 12966 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 12967 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12968 | {__LINE__, |
| 12969 | kProxy, |
| 12970 | AUTH_ASYNC, |
| 12971 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12972 | kServer, |
| 12973 | AUTH_ASYNC, |
| 12974 | ERR_INVALID_AUTH_CREDENTIALS, |
| 12975 | 4, |
| 12976 | kNoSSL, |
| 12977 | {TestRound(kGetProxy, kProxyChallenge, OK), |
| 12978 | TestRound(kGetProxy, kProxyChallenge, OK), |
| 12979 | TestRound(kGetProxyAuth, kServerChallenge, OK), |
| 12980 | TestRound(kGetProxyAuth, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12981 | // Non-authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12982 | {__LINE__, |
| 12983 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12984 | AUTH_NONE, |
| 12985 | OK, |
| 12986 | kSecureServer, |
| 12987 | AUTH_NONE, |
| 12988 | OK, |
| 12989 | 1, |
| 12990 | 0, |
| 12991 | {TestRound(kGet, kSuccess, OK)}}, |
| 12992 | // Authenticating HTTPS server with a direct connection. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 12993 | {__LINE__, |
| 12994 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 12995 | AUTH_NONE, |
| 12996 | OK, |
| 12997 | kSecureServer, |
| 12998 | AUTH_SYNC, |
| 12999 | OK, |
| 13000 | 2, |
| 13001 | 0, |
| 13002 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13003 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13004 | {__LINE__, |
| 13005 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13006 | AUTH_NONE, |
| 13007 | OK, |
| 13008 | kSecureServer, |
| 13009 | AUTH_SYNC, |
| 13010 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13011 | 2, |
| 13012 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13013 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13014 | {__LINE__, |
| 13015 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13016 | AUTH_NONE, |
| 13017 | OK, |
| 13018 | kSecureServer, |
| 13019 | AUTH_ASYNC, |
| 13020 | OK, |
| 13021 | 2, |
| 13022 | 0, |
| 13023 | {TestRound(kGet, kServerChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13024 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13025 | {__LINE__, |
| 13026 | nullptr, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13027 | AUTH_NONE, |
| 13028 | OK, |
| 13029 | kSecureServer, |
| 13030 | AUTH_ASYNC, |
| 13031 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13032 | 2, |
| 13033 | 0, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13034 | {TestRound(kGet, kServerChallenge, OK), TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13035 | // Non-authenticating HTTPS server with a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13036 | {__LINE__, |
| 13037 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13038 | AUTH_NONE, |
| 13039 | OK, |
| 13040 | kSecureServer, |
| 13041 | AUTH_NONE, |
| 13042 | OK, |
| 13043 | 1, |
| 13044 | 0, |
| 13045 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
| 13046 | // Authenticating HTTPS server through a non-authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13047 | {__LINE__, |
| 13048 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13049 | AUTH_NONE, |
| 13050 | OK, |
| 13051 | kSecureServer, |
| 13052 | AUTH_SYNC, |
| 13053 | OK, |
| 13054 | 2, |
| 13055 | 0, |
| 13056 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13057 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13058 | {__LINE__, |
| 13059 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13060 | AUTH_NONE, |
| 13061 | OK, |
| 13062 | kSecureServer, |
| 13063 | AUTH_SYNC, |
| 13064 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13065 | 2, |
| 13066 | 0, |
| 13067 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13068 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13069 | {__LINE__, |
| 13070 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13071 | AUTH_NONE, |
| 13072 | OK, |
| 13073 | kSecureServer, |
| 13074 | AUTH_ASYNC, |
| 13075 | OK, |
| 13076 | 2, |
| 13077 | 0, |
| 13078 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13079 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13080 | {__LINE__, |
| 13081 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13082 | AUTH_NONE, |
| 13083 | OK, |
| 13084 | kSecureServer, |
| 13085 | AUTH_ASYNC, |
| 13086 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13087 | 2, |
| 13088 | 0, |
| 13089 | {TestRound(kConnect, kProxyConnected, OK, &kGet, &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13090 | TestRound(kGet, kSuccess, OK)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13091 | // Non-Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13092 | {__LINE__, |
| 13093 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13094 | AUTH_SYNC, |
| 13095 | OK, |
| 13096 | kSecureServer, |
| 13097 | AUTH_NONE, |
| 13098 | OK, |
| 13099 | 2, |
| 13100 | 1, |
| 13101 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13102 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13103 | {__LINE__, |
| 13104 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13105 | AUTH_SYNC, |
| 13106 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13107 | kSecureServer, |
| 13108 | AUTH_NONE, |
| 13109 | OK, |
| 13110 | 2, |
| 13111 | kNoSSL, |
| 13112 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13113 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13114 | {__LINE__, |
| 13115 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13116 | AUTH_SYNC, |
| 13117 | ERR_UNSUPPORTED_AUTH_SCHEME, |
| 13118 | kSecureServer, |
| 13119 | AUTH_NONE, |
| 13120 | OK, |
| 13121 | 2, |
| 13122 | kNoSSL, |
| 13123 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13124 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13125 | {__LINE__, |
| 13126 | kProxy, |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13127 | AUTH_SYNC, |
| 13128 | ERR_UNEXPECTED, |
| 13129 | kSecureServer, |
| 13130 | AUTH_NONE, |
| 13131 | OK, |
| 13132 | 2, |
| 13133 | kNoSSL, |
| 13134 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13135 | TestRound(kConnect, kProxyConnected, ERR_UNEXPECTED)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13136 | {__LINE__, |
| 13137 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13138 | AUTH_ASYNC, |
| 13139 | OK, |
| 13140 | kSecureServer, |
| 13141 | AUTH_NONE, |
| 13142 | OK, |
| 13143 | 2, |
| 13144 | 1, |
| 13145 | {TestRound(kConnect, kProxyChallenge, OK), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13146 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13147 | {__LINE__, |
| 13148 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13149 | AUTH_ASYNC, |
| 13150 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13151 | kSecureServer, |
| 13152 | AUTH_NONE, |
| 13153 | OK, |
| 13154 | 2, |
| 13155 | kNoSSL, |
| 13156 | {TestRound(kConnect, kProxyChallenge, OK), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13157 | TestRound(kConnect, kProxyConnected, OK, &kGet, &kSuccess)}}, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13158 | // Authenticating HTTPS server through an authenticating proxy. |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13159 | {__LINE__, |
| 13160 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13161 | AUTH_SYNC, |
| 13162 | OK, |
| 13163 | kSecureServer, |
| 13164 | AUTH_SYNC, |
| 13165 | OK, |
| 13166 | 3, |
| 13167 | 1, |
| 13168 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13169 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13170 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13171 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13172 | {__LINE__, |
| 13173 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13174 | AUTH_SYNC, |
| 13175 | OK, |
| 13176 | kSecureServer, |
| 13177 | AUTH_SYNC, |
| 13178 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13179 | 3, |
| 13180 | 1, |
| 13181 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13182 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13183 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13184 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13185 | {__LINE__, |
| 13186 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13187 | AUTH_ASYNC, |
| 13188 | OK, |
| 13189 | kSecureServer, |
| 13190 | AUTH_SYNC, |
| 13191 | OK, |
| 13192 | 3, |
| 13193 | 1, |
| 13194 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13195 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13196 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13197 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13198 | {__LINE__, |
| 13199 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13200 | AUTH_ASYNC, |
| 13201 | OK, |
| 13202 | kSecureServer, |
| 13203 | AUTH_SYNC, |
| 13204 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13205 | 3, |
| 13206 | 1, |
| 13207 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13208 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13209 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13210 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13211 | {__LINE__, |
| 13212 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13213 | AUTH_SYNC, |
| 13214 | OK, |
| 13215 | kSecureServer, |
| 13216 | AUTH_ASYNC, |
| 13217 | OK, |
| 13218 | 3, |
| 13219 | 1, |
| 13220 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13221 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13222 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13223 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13224 | {__LINE__, |
| 13225 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13226 | AUTH_SYNC, |
| 13227 | OK, |
| 13228 | kSecureServer, |
| 13229 | AUTH_ASYNC, |
| 13230 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13231 | 3, |
| 13232 | 1, |
| 13233 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13234 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13235 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13236 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13237 | {__LINE__, |
| 13238 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13239 | AUTH_ASYNC, |
| 13240 | OK, |
| 13241 | kSecureServer, |
| 13242 | AUTH_ASYNC, |
| 13243 | OK, |
| 13244 | 3, |
| 13245 | 1, |
| 13246 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13247 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13248 | &kServerChallenge), |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13249 | TestRound(kGetAuth, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13250 | {__LINE__, |
| 13251 | kProxy, |
asanka | c9307619 | 2016-10-03 15:46:02 | [diff] [blame] | 13252 | AUTH_ASYNC, |
| 13253 | OK, |
| 13254 | kSecureServer, |
| 13255 | AUTH_ASYNC, |
| 13256 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13257 | 3, |
| 13258 | 1, |
| 13259 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13260 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13261 | &kServerChallenge), |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13262 | TestRound(kGet, kSuccess, OK)}}, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13263 | {__LINE__, |
| 13264 | kProxy, |
| 13265 | AUTH_ASYNC, |
| 13266 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13267 | kSecureServer, |
| 13268 | AUTH_ASYNC, |
| 13269 | ERR_INVALID_AUTH_CREDENTIALS, |
| 13270 | 4, |
| 13271 | 2, |
| 13272 | {TestRound(kConnect, kProxyChallenge, OK), |
| 13273 | TestRound(kConnect, kProxyChallenge, OK), |
| 13274 | TestRound(kConnectProxyAuth, kProxyConnected, OK, &kGet, |
| 13275 | &kServerChallenge), |
| 13276 | TestRound(kGet, kSuccess, OK)}}, |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13277 | }; |
| 13278 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13279 | for (const auto& test_config : test_configs) { |
| 13280 | SCOPED_TRACE(::testing::Message() << "Test config at " |
| 13281 | << test_config.line_number); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13282 | HttpAuthHandlerMock::Factory* auth_factory( |
| 13283 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13284 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 13285 | SSLInfo empty_ssl_info; |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 13286 | |
| 13287 | // Set up authentication handlers as necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13288 | if (test_config.proxy_auth_timing != AUTH_NONE) { |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13289 | for (int n = 0; n < 3; n++) { |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13290 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 13291 | std::string auth_challenge = "Mock realm=proxy"; |
| 13292 | GURL origin(test_config.proxy_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13293 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13294 | auth_challenge.end()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13295 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_PROXY, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13296 | empty_ssl_info, origin, |
| 13297 | NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13298 | auth_handler->SetGenerateExpectation( |
| 13299 | test_config.proxy_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13300 | n == 0 ? test_config.first_generate_proxy_token_rv : OK); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13301 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_PROXY); |
| 13302 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13303 | } |
| 13304 | if (test_config.server_auth_timing != AUTH_NONE) { |
[email protected] | 3fd9dae | 2010-06-21 11:39:00 | [diff] [blame] | 13305 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13306 | std::string auth_challenge = "Mock realm=server"; |
| 13307 | GURL origin(test_config.server_url); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13308 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13309 | auth_challenge.end()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13310 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13311 | empty_ssl_info, origin, |
| 13312 | NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13313 | auth_handler->SetGenerateExpectation( |
| 13314 | test_config.server_auth_timing == AUTH_ASYNC, |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13315 | test_config.first_generate_server_token_rv); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13316 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13317 | |
| 13318 | // The second handler always succeeds. It should only be used where there |
| 13319 | // are multiple auth sessions for server auth in the same network |
| 13320 | // transaction using the same auth scheme. |
| 13321 | std::unique_ptr<HttpAuthHandlerMock> second_handler = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13322 | std::make_unique<HttpAuthHandlerMock>(); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13323 | second_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
| 13324 | empty_ssl_info, origin, |
| 13325 | NetLogWithSource()); |
| 13326 | second_handler->SetGenerateExpectation(true, OK); |
| 13327 | auth_factory->AddMockHandler(second_handler.release(), |
| 13328 | HttpAuth::AUTH_SERVER); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13329 | } |
| 13330 | if (test_config.proxy_url) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13331 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13332 | ProxyResolutionService::CreateFixed(test_config.proxy_url, |
| 13333 | TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13334 | } else { |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 13335 | session_deps_.proxy_resolution_service = |
| 13336 | ProxyResolutionService::CreateDirect(); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13337 | } |
| 13338 | |
| 13339 | HttpRequestInfo request; |
| 13340 | request.method = "GET"; |
| 13341 | request.url = GURL(test_config.server_url); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13342 | request.traffic_annotation = |
| 13343 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13344 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13345 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13346 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13347 | SSLSocketDataProvider ssl_socket_data_provider(SYNCHRONOUS, OK); |
| 13348 | |
| 13349 | std::vector<std::vector<MockRead>> mock_reads(1); |
| 13350 | std::vector<std::vector<MockWrite>> mock_writes(1); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13351 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 13352 | SCOPED_TRACE(round); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13353 | const TestRound& read_write_round = test_config.rounds[round]; |
| 13354 | |
| 13355 | // Set up expected reads and writes. |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13356 | mock_reads.back().push_back(read_write_round.read); |
| 13357 | mock_writes.back().push_back(read_write_round.write); |
| 13358 | |
| 13359 | // kProxyChallenge uses Proxy-Connection: close which means that the |
| 13360 | // socket is closed and a new one will be created for the next request. |
mmenke | e71e1533 | 2015-10-07 16:39:54 | [diff] [blame] | 13361 | if (read_write_round.read.data == kProxyChallenge.data) { |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13362 | mock_reads.push_back(std::vector<MockRead>()); |
| 13363 | mock_writes.push_back(std::vector<MockWrite>()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13364 | } |
| 13365 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13366 | if (read_write_round.extra_read) { |
| 13367 | mock_reads.back().push_back(*read_write_round.extra_read); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13368 | } |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13369 | if (read_write_round.extra_write) { |
| 13370 | mock_writes.back().push_back(*read_write_round.extra_write); |
| 13371 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13372 | |
| 13373 | // Add an SSL sequence if necessary. |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13374 | if (round >= test_config.first_ssl_round) |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13375 | session_deps_.socket_factory->AddSSLSocketDataProvider( |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13376 | &ssl_socket_data_provider); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13377 | } |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13378 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13379 | std::vector<std::unique_ptr<StaticSocketDataProvider>> data_providers; |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13380 | for (size_t i = 0; i < mock_reads.size(); ++i) { |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13381 | data_providers.push_back(std::make_unique<StaticSocketDataProvider>( |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13382 | mock_reads[i], mock_writes[i])); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13383 | session_deps_.socket_factory->AddSocketDataProvider( |
olli.raula | 525048c | 2015-12-10 07:38:32 | [diff] [blame] | 13384 | data_providers.back().get()); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13385 | } |
| 13386 | |
mmenke | cc2298e | 2015-12-07 18:20:18 | [diff] [blame] | 13387 | // Transaction must be created after DataProviders, so it's destroyed before |
| 13388 | // they are as well. |
| 13389 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 13390 | |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13391 | for (int round = 0; round < test_config.num_auth_rounds; ++round) { |
davidben | 8c7089a | 2017-04-17 20:38:22 | [diff] [blame] | 13392 | SCOPED_TRACE(round); |
rch | cb68dc6 | 2015-05-21 04:45:36 | [diff] [blame] | 13393 | const TestRound& read_write_round = test_config.rounds[round]; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13394 | // Start or restart the transaction. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13395 | TestCompletionCallback callback; |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13396 | int rv; |
| 13397 | if (round == 0) { |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13398 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13399 | } else { |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13400 | rv = trans.RestartWithAuth( |
| 13401 | AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13402 | } |
| 13403 | if (rv == ERR_IO_PENDING) |
| 13404 | rv = callback.WaitForResult(); |
| 13405 | |
| 13406 | // Compare results with expected data. |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13407 | EXPECT_THAT(rv, IsError(read_write_round.expected_rv)); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13408 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
ttuttle | c0c82849 | 2015-05-15 01:25:55 | [diff] [blame] | 13409 | if (read_write_round.expected_rv != OK) { |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13410 | EXPECT_EQ(round + 1, test_config.num_auth_rounds); |
| 13411 | continue; |
| 13412 | } |
| 13413 | if (round + 1 < test_config.num_auth_rounds) { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13414 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13415 | } else { |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13416 | EXPECT_FALSE(response->auth_challenge); |
asanka | e2257db | 2016-10-11 22:03:16 | [diff] [blame] | 13417 | EXPECT_FALSE(trans.IsReadyToRestartForAuth()); |
[email protected] | 044de064 | 2010-06-17 10:42:15 | [diff] [blame] | 13418 | } |
| 13419 | } |
[email protected] | e5ae96a | 2010-04-14 20:12:45 | [diff] [blame] | 13420 | } |
| 13421 | } |
| 13422 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13423 | TEST_F(HttpNetworkTransactionTest, MultiRoundAuth) { |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13424 | // Do multi-round authentication and make sure it works correctly. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13425 | HttpAuthHandlerMock::Factory* auth_factory( |
| 13426 | new HttpAuthHandlerMock::Factory()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13427 | session_deps_.http_auth_handler_factory.reset(auth_factory); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 13428 | session_deps_.proxy_resolution_service = |
| 13429 | ProxyResolutionService::CreateDirect(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13430 | session_deps_.host_resolver->rules()->AddRule("www.example.com", "10.0.0.1"); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13431 | |
| 13432 | HttpAuthHandlerMock* auth_handler(new HttpAuthHandlerMock()); |
| 13433 | auth_handler->set_connection_based(true); |
| 13434 | std::string auth_challenge = "Mock realm=server"; |
| 13435 | GURL origin("http://www.example.com"); |
[email protected] | df41d0d8 | 2014-03-13 00:43:24 | [diff] [blame] | 13436 | HttpAuthChallengeTokenizer tokenizer(auth_challenge.begin(), |
| 13437 | auth_challenge.end()); |
asanka | 5ffd5d7 | 2016-03-23 16:20:49 | [diff] [blame] | 13438 | SSLInfo empty_ssl_info; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13439 | auth_handler->InitFromChallenge(&tokenizer, HttpAuth::AUTH_SERVER, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13440 | empty_ssl_info, origin, NetLogWithSource()); |
[email protected] | 2d01c26 | 2011-08-11 23:07:08 | [diff] [blame] | 13441 | auth_factory->AddMockHandler(auth_handler, HttpAuth::AUTH_SERVER); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13442 | |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13443 | int rv = OK; |
| 13444 | const HttpResponseInfo* response = NULL; |
| 13445 | HttpRequestInfo request; |
| 13446 | request.method = "GET"; |
| 13447 | request.url = origin; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13448 | request.traffic_annotation = |
| 13449 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13450 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13451 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13452 | |
| 13453 | // Use a TCP Socket Pool with only one connection per group. This is used |
| 13454 | // to validate that the TCP socket is not released to the pool between |
| 13455 | // each round of multi-round authentication. |
mmenke | e65e7af | 2015-10-13 17:16:42 | [diff] [blame] | 13456 | HttpNetworkSessionPeer session_peer(session.get()); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13457 | TransportClientSocketPool* transport_pool = new TransportClientSocketPool( |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13458 | 50, // Max sockets for pool |
| 13459 | 1, // Max sockets per group |
tbansal | 7b403bcc | 2016-04-13 22:33:21 | [diff] [blame] | 13460 | session_deps_.host_resolver.get(), session_deps_.socket_factory.get(), |
| 13461 | NULL, session_deps_.net_log); |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13462 | auto mock_pool_manager = std::make_unique<MockClientSocketPoolManager>(); |
[email protected] | a42dbd14 | 2011-11-17 16:42:02 | [diff] [blame] | 13463 | mock_pool_manager->SetTransportSocketPool(transport_pool); |
dcheng | c7eeda42 | 2015-12-26 03:56:48 | [diff] [blame] | 13464 | session_peer.SetClientSocketPoolManager(std::move(mock_pool_manager)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13465 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13466 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13467 | TestCompletionCallback callback; |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13468 | |
| 13469 | const MockWrite kGet( |
| 13470 | "GET / HTTP/1.1\r\n" |
| 13471 | "Host: www.example.com\r\n" |
| 13472 | "Connection: keep-alive\r\n\r\n"); |
| 13473 | const MockWrite kGetAuth( |
| 13474 | "GET / HTTP/1.1\r\n" |
| 13475 | "Host: www.example.com\r\n" |
| 13476 | "Connection: keep-alive\r\n" |
| 13477 | "Authorization: auth_token\r\n\r\n"); |
| 13478 | |
| 13479 | const MockRead kServerChallenge( |
| 13480 | "HTTP/1.1 401 Unauthorized\r\n" |
| 13481 | "WWW-Authenticate: Mock realm=server\r\n" |
| 13482 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13483 | "Content-Length: 14\r\n\r\n" |
| 13484 | "Unauthorized\r\n"); |
| 13485 | const MockRead kSuccess( |
| 13486 | "HTTP/1.1 200 OK\r\n" |
| 13487 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 13488 | "Content-Length: 3\r\n\r\n" |
| 13489 | "Yes"); |
| 13490 | |
| 13491 | MockWrite writes[] = { |
| 13492 | // First round |
| 13493 | kGet, |
| 13494 | // Second round |
| 13495 | kGetAuth, |
| 13496 | // Third round |
| 13497 | kGetAuth, |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13498 | // Fourth round |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13499 | kGetAuth, |
| 13500 | // Competing request |
| 13501 | kGet, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13502 | }; |
| 13503 | MockRead reads[] = { |
| 13504 | // First round |
| 13505 | kServerChallenge, |
| 13506 | // Second round |
| 13507 | kServerChallenge, |
| 13508 | // Third round |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13509 | kServerChallenge, |
| 13510 | // Fourth round |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13511 | kSuccess, |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13512 | // Competing response |
| 13513 | kSuccess, |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13514 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13515 | StaticSocketDataProvider data_provider(reads, writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13516 | session_deps_.socket_factory->AddSocketDataProvider(&data_provider); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13517 | |
thestig | 9d3bb0c | 2015-01-24 00:49:51 | [diff] [blame] | 13518 | const char kSocketGroup[] = "www.example.com:80"; |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13519 | |
| 13520 | // First round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13521 | auth_handler->SetGenerateExpectation(false, OK); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13522 | rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13523 | if (rv == ERR_IO_PENDING) |
| 13524 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13525 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13526 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13527 | ASSERT_TRUE(response); |
| 13528 | EXPECT_TRUE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13529 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13530 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13531 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13532 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13533 | // In between rounds, another request comes in for the same domain. |
| 13534 | // It should not be able to grab the TCP socket that trans has already |
| 13535 | // claimed. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13536 | HttpNetworkTransaction trans_compete(DEFAULT_PRIORITY, session.get()); |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13537 | TestCompletionCallback callback_compete; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13538 | rv = trans_compete.Start(&request, callback_compete.callback(), |
| 13539 | NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13540 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13541 | // callback_compete.WaitForResult at this point would stall forever, |
| 13542 | // since the HttpNetworkTransaction does not release the request back to |
| 13543 | // the pool until after authentication completes. |
| 13544 | |
| 13545 | // Second round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13546 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13547 | rv = trans.RestartWithAuth(AuthCredentials(kFoo, kBar), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13548 | if (rv == ERR_IO_PENDING) |
| 13549 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13550 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13551 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13552 | ASSERT_TRUE(response); |
| 13553 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13554 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13555 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13556 | auth_handler->state()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13557 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13558 | // Third round of authentication. |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13559 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13560 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13561 | if (rv == ERR_IO_PENDING) |
| 13562 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13563 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13564 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13565 | ASSERT_TRUE(response); |
| 13566 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13567 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13568 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_GENERATE_AUTH_TOKEN, |
| 13569 | auth_handler->state()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13570 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13571 | // Fourth round of authentication, which completes successfully. |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13572 | auth_handler->SetGenerateExpectation(false, OK); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13573 | rv = trans.RestartWithAuth(AuthCredentials(), callback.callback()); |
[email protected] | eca50e12 | 2010-09-11 14:03:30 | [diff] [blame] | 13574 | if (rv == ERR_IO_PENDING) |
| 13575 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13576 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13577 | response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13578 | ASSERT_TRUE(response); |
| 13579 | EXPECT_FALSE(response->auth_challenge); |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13580 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13581 | |
asanka | 463ca426 | 2016-11-16 02:34:31 | [diff] [blame] | 13582 | // In WAIT_FOR_CHALLENGE, although in reality the auth handler is done. A real |
| 13583 | // auth handler should transition to a DONE state in concert with the remote |
| 13584 | // server. But that's not something we can test here with a mock handler. |
| 13585 | EXPECT_EQ(HttpAuthHandlerMock::State::WAIT_FOR_CHALLENGE, |
| 13586 | auth_handler->state()); |
| 13587 | |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13588 | // Read the body since the fourth round was successful. This will also |
| 13589 | // release the socket back to the pool. |
Victor Costan | 9c7302b | 2018-08-27 16:39:44 | [diff] [blame] | 13590 | scoped_refptr<IOBufferWithSize> io_buf = |
| 13591 | base::MakeRefCounted<IOBufferWithSize>(50); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13592 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13593 | if (rv == ERR_IO_PENDING) |
| 13594 | rv = callback.WaitForResult(); |
| 13595 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13596 | rv = trans.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13597 | EXPECT_EQ(0, rv); |
| 13598 | // There are still 0 idle sockets, since the trans_compete transaction |
| 13599 | // will be handed it immediately after trans releases it to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13600 | EXPECT_EQ(0, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13601 | |
| 13602 | // The competing request can now finish. Wait for the headers and then |
| 13603 | // read the body. |
| 13604 | rv = callback_compete.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13605 | EXPECT_THAT(rv, IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13606 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13607 | if (rv == ERR_IO_PENDING) |
| 13608 | rv = callback.WaitForResult(); |
| 13609 | EXPECT_EQ(3, rv); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13610 | rv = trans_compete.Read(io_buf.get(), io_buf->size(), callback.callback()); |
[email protected] | 7ef4cbbb | 2011-02-06 11:19:10 | [diff] [blame] | 13611 | EXPECT_EQ(0, rv); |
| 13612 | |
| 13613 | // Finally, the socket is released to the group. |
[email protected] | ab73904 | 2011-04-07 15:22:28 | [diff] [blame] | 13614 | EXPECT_EQ(1, transport_pool->IdleSocketCountInGroup(kSocketGroup)); |
[email protected] | c871bce9 | 2010-07-15 21:51:14 | [diff] [blame] | 13615 | } |
| 13616 | |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13617 | // This tests the case that a request is issued via http instead of spdy after |
| 13618 | // npn is negotiated. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13619 | TEST_F(HttpNetworkTransactionTest, NpnWithHttpOverSSL) { |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13620 | HttpRequestInfo request; |
| 13621 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13622 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13623 | request.traffic_annotation = |
| 13624 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13625 | |
| 13626 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13627 | MockWrite( |
| 13628 | "GET / HTTP/1.1\r\n" |
| 13629 | "Host: www.example.org\r\n" |
| 13630 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13631 | }; |
| 13632 | |
| 13633 | MockRead data_reads[] = { |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13634 | MockRead("HTTP/1.1 200 OK\r\n"), |
bnc | 2df4b52 | 2016-07-08 18:17:43 | [diff] [blame] | 13635 | MockRead(kAlternativeServiceHttpHeader), |
bnc | c958faa | 2015-07-31 18:14:52 | [diff] [blame] | 13636 | MockRead("\r\n"), |
| 13637 | MockRead("hello world"), |
| 13638 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13639 | }; |
| 13640 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13641 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13642 | ssl.next_proto = kProtoHTTP11; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13643 | |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13644 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13645 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13646 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13647 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13648 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13649 | TestCompletionCallback callback; |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13650 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13651 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13652 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13653 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13654 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13655 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13656 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13657 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13658 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13659 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13660 | ASSERT_TRUE(response); |
| 13661 | ASSERT_TRUE(response->headers); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13662 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13663 | |
| 13664 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13665 | ASSERT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13666 | EXPECT_EQ("hello world", response_data); |
| 13667 | |
| 13668 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 13669 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 65041fa | 2010-05-21 06:56:53 | [diff] [blame] | 13670 | } |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13671 | |
bnc | 55ff9da | 2015-08-19 18:42:35 | [diff] [blame] | 13672 | // Simulate the SSL handshake completing with an NPN negotiation followed by an |
| 13673 | // immediate server closing of the socket. |
| 13674 | // Regression test for https://crbug.com/46369. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13675 | TEST_F(HttpNetworkTransactionTest, SpdyPostNPNServerHangup) { |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13676 | HttpRequestInfo request; |
| 13677 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13678 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13679 | request.traffic_annotation = |
| 13680 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13681 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13682 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 13683 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13684 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13685 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 13686 | spdy::SpdySerializedFrame req( |
| 13687 | spdy_util_.ConstructSpdyGet(nullptr, 0, 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 13688 | MockWrite spdy_writes[] = {CreateMockWrite(req, 1)}; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13689 | |
| 13690 | MockRead spdy_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13691 | MockRead(SYNCHRONOUS, 0, 0) // Not async - return 0 immediately. |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13692 | }; |
| 13693 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13694 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13695 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13696 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13697 | TestCompletionCallback callback; |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13698 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13699 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13700 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13701 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13702 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13703 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 13704 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 26ef658 | 2010-06-24 02:30:47 | [diff] [blame] | 13705 | } |
[email protected] | 65d3438 | 2010-07-01 18:12:26 | [diff] [blame] | 13706 | |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13707 | // A subclass of HttpAuthHandlerMock that records the request URL when |
| 13708 | // it gets it. This is needed since the auth handler may get destroyed |
| 13709 | // before we get a chance to query it. |
| 13710 | class UrlRecordingHttpAuthHandlerMock : public HttpAuthHandlerMock { |
| 13711 | public: |
| 13712 | explicit UrlRecordingHttpAuthHandlerMock(GURL* url) : url_(url) {} |
| 13713 | |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 13714 | ~UrlRecordingHttpAuthHandlerMock() override = default; |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13715 | |
| 13716 | protected: |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13717 | int GenerateAuthTokenImpl(const AuthCredentials* credentials, |
| 13718 | const HttpRequestInfo* request, |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 13719 | CompletionOnceCallback callback, |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 13720 | std::string* auth_token) override { |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13721 | *url_ = request->url; |
| 13722 | return HttpAuthHandlerMock::GenerateAuthTokenImpl( |
Bence Béky | 7236fb7 | 2018-08-01 14:35:09 | [diff] [blame] | 13723 | credentials, request, std::move(callback), auth_token); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 13724 | } |
| 13725 | |
| 13726 | private: |
| 13727 | GURL* url_; |
| 13728 | }; |
| 13729 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13730 | // Test that if we cancel the transaction as the connection is completing, that |
| 13731 | // everything tears down correctly. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13732 | TEST_F(HttpNetworkTransactionTest, SimpleCancel) { |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13733 | // Setup everything about the connection to complete synchronously, so that |
| 13734 | // after calling HttpNetworkTransaction::Start, the only thing we're waiting |
| 13735 | // for is the callback from the HttpStreamRequest. |
| 13736 | // Then cancel the transaction. |
| 13737 | // Verify that we don't crash. |
[email protected] | d973e99a | 2012-02-17 21:02:36 | [diff] [blame] | 13738 | MockConnect mock_connect(SYNCHRONOUS, OK); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13739 | MockRead data_reads[] = { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13740 | MockRead(SYNCHRONOUS, "HTTP/1.0 200 OK\r\n\r\n"), |
| 13741 | MockRead(SYNCHRONOUS, "hello world"), |
| 13742 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13743 | }; |
| 13744 | |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13745 | HttpRequestInfo request; |
| 13746 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13747 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13748 | request.traffic_annotation = |
| 13749 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13750 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13751 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 13752 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 13753 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 13754 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13755 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13756 | data.set_connect_data(mock_connect); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13757 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13758 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13759 | TestCompletionCallback callback; |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13760 | |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13761 | BoundTestNetLog log; |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13762 | int rv = trans->Start(&request, callback.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13763 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8e6441ca | 2010-08-19 05:56:38 | [diff] [blame] | 13764 | trans.reset(); // Cancel the transaction here. |
| 13765 | |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13766 | base::RunLoop().RunUntilIdle(); |
[email protected] | f45c1ee | 2010-08-03 00:54:30 | [diff] [blame] | 13767 | } |
| 13768 | |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13769 | // Test that if a transaction is cancelled after receiving the headers, the |
| 13770 | // stream is drained properly and added back to the socket pool. The main |
| 13771 | // purpose of this test is to make sure that an HttpStreamParser can be read |
| 13772 | // from after the HttpNetworkTransaction and the objects it owns have been |
| 13773 | // deleted. |
| 13774 | // See http://crbug.com/368418 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13775 | TEST_F(HttpNetworkTransactionTest, CancelAfterHeaders) { |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13776 | MockRead data_reads[] = { |
| 13777 | MockRead(ASYNC, "HTTP/1.1 200 OK\r\n"), |
| 13778 | MockRead(ASYNC, "Content-Length: 2\r\n"), |
| 13779 | MockRead(ASYNC, "Connection: Keep-Alive\r\n\r\n"), |
| 13780 | MockRead(ASYNC, "1"), |
| 13781 | // 2 async reads are necessary to trigger a ReadResponseBody call after the |
| 13782 | // HttpNetworkTransaction has been deleted. |
| 13783 | MockRead(ASYNC, "2"), |
| 13784 | MockRead(SYNCHRONOUS, ERR_IO_PENDING), // Should never read this. |
| 13785 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13786 | StaticSocketDataProvider data(data_reads, base::span<MockWrite>()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13787 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 13788 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13789 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13790 | |
| 13791 | { |
| 13792 | HttpRequestInfo request; |
| 13793 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13794 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13795 | request.traffic_annotation = |
| 13796 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13797 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13798 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13799 | TestCompletionCallback callback; |
| 13800 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 13801 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13802 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13803 | callback.WaitForResult(); |
| 13804 | |
| 13805 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13806 | ASSERT_TRUE(response); |
| 13807 | EXPECT_TRUE(response->headers); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13808 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 13809 | |
| 13810 | // The transaction and HttpRequestInfo are deleted. |
| 13811 | } |
| 13812 | |
| 13813 | // Let the HttpResponseBodyDrainer drain the socket. |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 13814 | base::RunLoop().RunUntilIdle(); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13815 | |
| 13816 | // Socket should now be idle, waiting to be reused. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 13817 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | ecab6e05 | 2014-05-16 14:58:12 | [diff] [blame] | 13818 | } |
| 13819 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13820 | // Test a basic GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13821 | TEST_F(HttpNetworkTransactionTest, ProxyGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13822 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13823 | ProxyResolutionService::CreateFixedFromPacResult( |
| 13824 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13825 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13826 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13827 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13828 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13829 | HttpRequestInfo request; |
| 13830 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13831 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13832 | request.traffic_annotation = |
| 13833 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13834 | |
| 13835 | MockWrite data_writes1[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13836 | MockWrite( |
| 13837 | "GET http://www.example.org/ HTTP/1.1\r\n" |
| 13838 | "Host: www.example.org\r\n" |
| 13839 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13840 | }; |
| 13841 | |
| 13842 | MockRead data_reads1[] = { |
| 13843 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13844 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13845 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13846 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13847 | }; |
| 13848 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13849 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13850 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13851 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13852 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13853 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13854 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13855 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13856 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13857 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13858 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13859 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13860 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13861 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13862 | |
| 13863 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13864 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13865 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13866 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13867 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13868 | |
| 13869 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13870 | EXPECT_EQ(200, response->headers->response_code()); |
| 13871 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13872 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13873 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13874 | HostPortPair::FromString("myproxy:70")), |
| 13875 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13876 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13877 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13878 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13879 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13880 | |
| 13881 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13882 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13883 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13884 | CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13885 | } |
| 13886 | |
| 13887 | // Test a basic HTTPS GET request through a proxy. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13888 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGet) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13889 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13890 | ProxyResolutionService::CreateFixedFromPacResult( |
| 13891 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 13892 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13893 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13894 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13895 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13896 | HttpRequestInfo request; |
| 13897 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 13898 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13899 | request.traffic_annotation = |
| 13900 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13901 | |
| 13902 | // Since we have proxy, should try to establish tunnel. |
| 13903 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13904 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 13905 | "Host: www.example.org:443\r\n" |
| 13906 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13907 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13908 | MockWrite("GET / HTTP/1.1\r\n" |
| 13909 | "Host: www.example.org\r\n" |
| 13910 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13911 | }; |
| 13912 | |
| 13913 | MockRead data_reads1[] = { |
| 13914 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 13915 | |
| 13916 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 13917 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 13918 | MockRead("Content-Length: 100\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13919 | MockRead(SYNCHRONOUS, OK), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13920 | }; |
| 13921 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 13922 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13923 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 13924 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 13925 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13926 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 13927 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13928 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13929 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13930 | BeforeHeadersSentHandler headers_handler; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13931 | trans.SetBeforeHeadersSentCallback( |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13932 | base::Bind(&BeforeHeadersSentHandler::OnBeforeHeadersSent, |
| 13933 | base::Unretained(&headers_handler))); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 13934 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13935 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13936 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13937 | |
| 13938 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 13939 | EXPECT_THAT(rv, IsOk()); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 13940 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13941 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13942 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13943 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 13944 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13945 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 13946 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 13947 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 13948 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13949 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13950 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 13951 | ASSERT_TRUE(response); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13952 | |
| 13953 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 13954 | EXPECT_EQ(200, response->headers->response_code()); |
| 13955 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 13956 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 13957 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 13958 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 13959 | HostPortPair::FromString("myproxy:70")), |
| 13960 | response->proxy_server); |
ryansturm | 49a8cb1 | 2016-06-15 16:51:09 | [diff] [blame] | 13961 | EXPECT_TRUE(headers_handler.observed_before_headers_sent()); |
| 13962 | EXPECT_TRUE(headers_handler.observed_before_headers_sent_with_proxy()); |
| 13963 | EXPECT_EQ("myproxy:70", headers_handler.observed_proxy_server_uri()); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13964 | |
| 13965 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 13966 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
[email protected] | 029c83b6 | 2013-01-24 05:28:20 | [diff] [blame] | 13967 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 13968 | CONNECT_TIMING_HAS_SSL_TIMES); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 13969 | } |
| 13970 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13971 | // Test a basic HTTPS GET request through a proxy, connecting to an IPv6 |
| 13972 | // literal host. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 13973 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetIPv6) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 13974 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 13975 | ProxyResolutionService::CreateFixedFromPacResult( |
| 13976 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13977 | BoundTestNetLog log; |
| 13978 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 13979 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13980 | |
| 13981 | HttpRequestInfo request; |
| 13982 | request.method = "GET"; |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 13983 | request.url = GURL("https://[::2]:443/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 13984 | request.traffic_annotation = |
| 13985 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13986 | |
| 13987 | // Since we have proxy, should try to establish tunnel. |
| 13988 | MockWrite data_writes1[] = { |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 13989 | MockWrite("CONNECT [::2]:443 HTTP/1.1\r\n" |
| 13990 | "Host: [::2]:443\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13991 | "Proxy-Connection: keep-alive\r\n\r\n"), |
| 13992 | |
| 13993 | MockWrite("GET / HTTP/1.1\r\n" |
Eric Roman | da790f9 | 2018-11-07 19:17:15 | [diff] [blame] | 13994 | "Host: [::2]\r\n" |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 13995 | "Connection: keep-alive\r\n\r\n"), |
| 13996 | }; |
| 13997 | |
| 13998 | MockRead data_reads1[] = { |
| 13999 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 14000 | |
| 14001 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 14002 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 14003 | MockRead("Content-Length: 100\r\n\r\n"), |
| 14004 | MockRead(SYNCHRONOUS, OK), |
| 14005 | }; |
| 14006 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14007 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14008 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14009 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 14010 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 14011 | |
| 14012 | TestCompletionCallback callback1; |
| 14013 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14014 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14015 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14016 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14017 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14018 | |
| 14019 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14020 | EXPECT_THAT(rv, IsOk()); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14021 | TestNetLogEntry::List entries; |
| 14022 | log.GetEntries(&entries); |
| 14023 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14024 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14025 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14026 | ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14027 | entries, pos, |
| 14028 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14029 | NetLogEventPhase::NONE); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14030 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14031 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14032 | ASSERT_TRUE(response); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14033 | |
| 14034 | EXPECT_TRUE(response->headers->IsKeepAlive()); |
| 14035 | EXPECT_EQ(200, response->headers->response_code()); |
| 14036 | EXPECT_EQ(100, response->headers->GetContentLength()); |
| 14037 | EXPECT_TRUE(HttpVersion(1, 1) == response->headers->GetHttpVersion()); |
| 14038 | EXPECT_TRUE(response->was_fetched_via_proxy); |
tbansal | 2ecbbc7 | 2016-10-06 17:15:47 | [diff] [blame] | 14039 | EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 14040 | HostPortPair::FromString("myproxy:70")), |
| 14041 | response->proxy_server); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14042 | |
| 14043 | LoadTimingInfo load_timing_info; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14044 | EXPECT_TRUE(trans.GetLoadTimingInfo(&load_timing_info)); |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14045 | TestLoadTimingNotReusedWithPac(load_timing_info, |
| 14046 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 14047 | } |
| 14048 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14049 | // Test a basic HTTPS GET request through a proxy, but the server hangs up |
| 14050 | // while establishing the tunnel. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14051 | TEST_F(HttpNetworkTransactionTest, ProxyTunnelGetHangup) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14052 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 14053 | "myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14054 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14055 | session_deps_.net_log = log.bound().net_log(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14056 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14057 | |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14058 | HttpRequestInfo request; |
| 14059 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14060 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14061 | request.traffic_annotation = |
| 14062 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14063 | |
| 14064 | // Since we have proxy, should try to establish tunnel. |
| 14065 | MockWrite data_writes1[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14066 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 14067 | "Host: www.example.org:443\r\n" |
| 14068 | "Proxy-Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14069 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 14070 | MockWrite("GET / HTTP/1.1\r\n" |
| 14071 | "Host: www.example.org\r\n" |
| 14072 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14073 | }; |
| 14074 | |
| 14075 | MockRead data_reads1[] = { |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14076 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14077 | MockRead(ASYNC, 0, 0), // EOF |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14078 | }; |
| 14079 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14080 | StaticSocketDataProvider data1(data_reads1, data_writes1); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14081 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14082 | SSLSocketDataProvider ssl(ASYNC, OK); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14083 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14084 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14085 | TestCompletionCallback callback1; |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14086 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14087 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 0b0bf03 | 2010-09-21 18:08:50 | [diff] [blame] | 14088 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14089 | int rv = trans.Start(&request, callback1.callback(), log.bound()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14090 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14091 | |
| 14092 | rv = callback1.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14093 | EXPECT_THAT(rv, IsError(ERR_EMPTY_RESPONSE)); |
mmenke | 43758e6 | 2015-05-04 21:09:46 | [diff] [blame] | 14094 | TestNetLogEntry::List entries; |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14095 | log.GetEntries(&entries); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14096 | size_t pos = ExpectLogContainsSomewhere( |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14097 | entries, 0, NetLogEventType::HTTP_TRANSACTION_SEND_TUNNEL_HEADERS, |
| 14098 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14099 | ExpectLogContainsSomewhere( |
[email protected] | b2fcd0e | 2010-12-01 15:19:40 | [diff] [blame] | 14100 | entries, pos, |
mikecirone | 8b85c43 | 2016-09-08 19:11:00 | [diff] [blame] | 14101 | NetLogEventType::HTTP_TRANSACTION_READ_TUNNEL_RESPONSE_HEADERS, |
| 14102 | NetLogEventPhase::NONE); |
[email protected] | 76a505b | 2010-08-25 06:23:00 | [diff] [blame] | 14103 | } |
| 14104 | |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14105 | // Test for crbug.com/55424. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14106 | TEST_F(HttpNetworkTransactionTest, PreconnectWithExistingSpdySession) { |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14107 | spdy::SpdySerializedFrame req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14108 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14109 | MockWrite spdy_writes[] = {CreateMockWrite(req, 0)}; |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14110 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14111 | spdy::SpdySerializedFrame resp(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 14112 | spdy::SpdySerializedFrame data(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14113 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14114 | CreateMockRead(resp, 1), CreateMockRead(data, 2), MockRead(ASYNC, 0, 3), |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14115 | }; |
| 14116 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14117 | SequencedSocketData spdy_data(spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14118 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14119 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14120 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 14121 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14122 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14123 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14124 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14125 | |
| 14126 | // Set up an initial SpdySession in the pool to reuse. |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14127 | HostPortPair host_port_pair("www.example.org", 443); |
[email protected] | e6d01765 | 2013-05-17 18:01:40 | [diff] [blame] | 14128 | SpdySessionKey key(host_port_pair, ProxyServer::Direct(), |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 14129 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 795cbf8 | 2013-07-22 09:37:27 | [diff] [blame] | 14130 | base::WeakPtr<SpdySession> spdy_session = |
Bence Béky | 0ef1556e | 2017-06-30 19:52:52 | [diff] [blame] | 14131 | CreateSpdySession(session.get(), key, NetLogWithSource()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14132 | |
| 14133 | HttpRequestInfo request; |
| 14134 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14135 | request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14136 | request.traffic_annotation = |
| 14137 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14138 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14139 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14140 | |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 14141 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14142 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14143 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14144 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 749eefa8 | 2010-09-13 22:14:03 | [diff] [blame] | 14145 | } |
| 14146 | |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14147 | // Given a net error, cause that error to be returned from the first Write() |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14148 | // call and verify that the HttpNetworkTransaction fails with that error. |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 14149 | void HttpNetworkTransactionTest::CheckErrorIsPassedBack( |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14150 | int error, IoMode mode) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14151 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14152 | request_info.url = GURL("https://www.example.com/"); |
| 14153 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14154 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14155 | request_info.traffic_annotation = |
| 14156 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14157 | |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14158 | SSLSocketDataProvider ssl_data(mode, OK); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14159 | MockWrite data_writes[] = { |
| 14160 | MockWrite(mode, error), |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14161 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14162 | StaticSocketDataProvider data(base::span<MockRead>(), data_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14163 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 14164 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14165 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14166 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14167 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14168 | |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14169 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14170 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14171 | if (rv == ERR_IO_PENDING) |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14172 | rv = callback.WaitForResult(); |
| 14173 | ASSERT_EQ(error, rv); |
| 14174 | } |
| 14175 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14176 | TEST_F(HttpNetworkTransactionTest, SSLWriteCertError) { |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14177 | // Just check a grab bag of cert errors. |
| 14178 | static const int kErrors[] = { |
| 14179 | ERR_CERT_COMMON_NAME_INVALID, |
| 14180 | ERR_CERT_AUTHORITY_INVALID, |
| 14181 | ERR_CERT_DATE_INVALID, |
| 14182 | }; |
| 14183 | for (size_t i = 0; i < arraysize(kErrors); i++) { |
[email protected] | 8ddf832 | 2012-02-23 18:08:06 | [diff] [blame] | 14184 | CheckErrorIsPassedBack(kErrors[i], ASYNC); |
| 14185 | CheckErrorIsPassedBack(kErrors[i], SYNCHRONOUS); |
[email protected] | 73b8dd22 | 2010-11-11 19:55:24 | [diff] [blame] | 14186 | } |
| 14187 | } |
| 14188 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14189 | // Ensure that a client certificate is removed from the SSL client auth |
| 14190 | // cache when: |
| 14191 | // 1) No proxy is involved. |
| 14192 | // 2) TLS False Start is disabled. |
| 14193 | // 3) The initial TLS handshake requests a client certificate. |
| 14194 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14195 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_NoFalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14196 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14197 | request_info.url = GURL("https://www.example.com/"); |
| 14198 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14199 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14200 | request_info.traffic_annotation = |
| 14201 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14202 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14203 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14204 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14205 | |
| 14206 | // [ssl_]data1 contains the data for the first SSL handshake. When a |
| 14207 | // CertificateRequest is received for the first time, the handshake will |
| 14208 | // be aborted to allow the caller to provide a certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14209 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14210 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14211 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14212 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14213 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14214 | |
| 14215 | // [ssl_]data2 contains the data for the second SSL handshake. When TLS |
| 14216 | // False Start is not being used, the result of the SSL handshake will be |
| 14217 | // returned as part of the SSLClientSocket::Connect() call. This test |
| 14218 | // matches the result of a server sending a handshake_failure alert, |
| 14219 | // rather than a Finished message, because it requires a client |
| 14220 | // certificate and none was supplied. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14221 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14222 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14223 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14224 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14225 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14226 | |
| 14227 | // [ssl_]data3 contains the data for the third SSL handshake. When a |
| 14228 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 14229 | // HttpNetworkTransaction will attempt to fallback to TLSv1.1 if the previous |
| 14230 | // connection was attempted with TLSv1.2. This is transparent to the caller |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14231 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 14232 | // requiring a client certificate, this fallback handshake should also |
| 14233 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14234 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14235 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14236 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14237 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14238 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14239 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14240 | // [ssl_]data4 contains the data for the fourth SSL handshake. When a |
| 14241 | // connection to a server fails during an SSL handshake, |
davidben | b937d6c | 2015-05-14 04:53:42 | [diff] [blame] | 14242 | // HttpNetworkTransaction will attempt to fallback to TLSv1 if the previous |
| 14243 | // connection was attempted with TLSv1.1. This is transparent to the caller |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14244 | // of the HttpNetworkTransaction. Because this test failure is due to |
| 14245 | // requiring a client certificate, this fallback handshake should also |
| 14246 | // fail. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14247 | SSLSocketDataProvider ssl_data4(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14248 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14249 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14250 | StaticSocketDataProvider data4; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14251 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14252 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14253 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14254 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14255 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14256 | // Begin the SSL handshake with the peer. This consumes ssl_data1. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14257 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14258 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14259 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14260 | |
| 14261 | // Complete the SSL handshake, which should abort due to requiring a |
| 14262 | // client certificate. |
| 14263 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14264 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14265 | |
| 14266 | // Indicate that no certificate should be supplied. From the perspective |
| 14267 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14268 | // certificate, so this is the same as supply a |
| 14269 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14270 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14271 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14272 | |
| 14273 | // Ensure the certificate was added to the client auth cache before |
| 14274 | // allowing the connection to continue restarting. |
| 14275 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14276 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14277 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14278 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14279 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14280 | |
| 14281 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14282 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 14283 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14284 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14285 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14286 | |
| 14287 | // Ensure that the client certificate is removed from the cache on a |
| 14288 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14289 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14290 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14291 | } |
| 14292 | |
| 14293 | // Ensure that a client certificate is removed from the SSL client auth |
| 14294 | // cache when: |
| 14295 | // 1) No proxy is involved. |
| 14296 | // 2) TLS False Start is enabled. |
| 14297 | // 3) The initial TLS handshake requests a client certificate. |
| 14298 | // 4) The client supplies an invalid/unacceptable certificate. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14299 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Direct_FalseStart) { |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14300 | HttpRequestInfo request_info; |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14301 | request_info.url = GURL("https://www.example.com/"); |
| 14302 | request_info.method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14303 | request_info.load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14304 | request_info.traffic_annotation = |
| 14305 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | cb9bf6ca | 2011-01-28 13:15:27 | [diff] [blame] | 14306 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14307 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14308 | cert_request->host_and_port = HostPortPair("www.example.com", 443); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14309 | |
| 14310 | // When TLS False Start is used, SSLClientSocket::Connect() calls will |
| 14311 | // return successfully after reading up to the peer's Certificate message. |
| 14312 | // This is to allow the caller to call SSLClientSocket::Write(), which can |
| 14313 | // enqueue application data to be sent in the same packet as the |
| 14314 | // ChangeCipherSpec and Finished messages. |
| 14315 | // The actual handshake will be finished when SSLClientSocket::Read() is |
| 14316 | // called, which expects to process the peer's ChangeCipherSpec and |
| 14317 | // Finished messages. If there was an error negotiating with the peer, |
| 14318 | // such as due to the peer requiring a client certificate when none was |
| 14319 | // supplied, the alert sent by the peer won't be processed until Read() is |
| 14320 | // called. |
| 14321 | |
| 14322 | // Like the non-False Start case, when a client certificate is requested by |
| 14323 | // the peer, the handshake is aborted during the Connect() call. |
| 14324 | // [ssl_]data1 represents the initial SSL handshake with the peer. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14325 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14326 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14327 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14328 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14329 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14330 | |
| 14331 | // When a client certificate is supplied, Connect() will not be aborted |
| 14332 | // when the peer requests the certificate. Instead, the handshake will |
| 14333 | // artificially succeed, allowing the caller to write the HTTP request to |
| 14334 | // the socket. The handshake messages are not processed until Read() is |
| 14335 | // called, which then detects that the handshake was aborted, due to the |
| 14336 | // peer sending a handshake_failure because it requires a client |
| 14337 | // certificate. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14338 | SSLSocketDataProvider ssl_data2(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14339 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14340 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14341 | MockRead data2_reads[] = { |
| 14342 | MockRead(ASYNC /* async */, ERR_SSL_PROTOCOL_ERROR), |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14343 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14344 | StaticSocketDataProvider data2(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14345 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14346 | |
| 14347 | // As described in ClientAuthCertCache_Direct_NoFalseStart, [ssl_]data3 is |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14348 | // the data for the SSL handshake once the TLSv1.1 connection falls back to |
| 14349 | // TLSv1. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14350 | SSLSocketDataProvider ssl_data3(ASYNC, OK); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14351 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14352 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14353 | StaticSocketDataProvider data3(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14354 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14355 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14356 | // [ssl_]data4 is the data for the SSL handshake once the TLSv1 connection |
| 14357 | // falls back to SSLv3. It has the same behaviour as [ssl_]data2. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14358 | SSLSocketDataProvider ssl_data4(ASYNC, OK); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14359 | ssl_data4.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14360 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data4); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14361 | StaticSocketDataProvider data4(data2_reads, base::span<MockWrite>()); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14362 | session_deps_.socket_factory->AddSocketDataProvider(&data4); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14363 | |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14364 | // Need one more if TLSv1.2 is enabled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14365 | SSLSocketDataProvider ssl_data5(ASYNC, OK); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14366 | ssl_data5.cert_request_info = cert_request.get(); |
| 14367 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data5); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14368 | StaticSocketDataProvider data5(data2_reads, base::span<MockWrite>()); |
[email protected] | 7799de1 | 2013-05-30 05:52:51 | [diff] [blame] | 14369 | session_deps_.socket_factory->AddSocketDataProvider(&data5); |
| 14370 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14371 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14372 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14373 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14374 | // Begin the initial SSL handshake. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14375 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14376 | int rv = trans.Start(&request_info, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14377 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14378 | |
| 14379 | // Complete the SSL handshake, which should abort due to requiring a |
| 14380 | // client certificate. |
| 14381 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14382 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14383 | |
| 14384 | // Indicate that no certificate should be supplied. From the perspective |
| 14385 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14386 | // certificate, so this is the same as supply a |
| 14387 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14388 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14389 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14390 | |
| 14391 | // Ensure the certificate was added to the client auth cache before |
| 14392 | // allowing the connection to continue restarting. |
| 14393 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14394 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14395 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14396 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14397 | ASSERT_FALSE(client_cert); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14398 | |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14399 | // Restart the handshake. This will consume ssl_data2, which fails, and |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14400 | // then consume ssl_data3 and ssl_data4, both of which should also fail. |
| 14401 | // The result code is checked against what ssl_data4 should return. |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14402 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14403 | ASSERT_THAT(rv, IsError(ERR_SSL_PROTOCOL_ERROR)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14404 | |
| 14405 | // Ensure that the client certificate is removed from the cache on a |
| 14406 | // handshake failure. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14407 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14408 | HostPortPair("www.example.com", 443), &client_cert, &client_private_key)); |
[email protected] | bd0b677 | 2011-01-11 19:59:30 | [diff] [blame] | 14409 | } |
| 14410 | |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14411 | // Ensure that a client certificate is removed from the SSL client auth |
| 14412 | // cache when: |
| 14413 | // 1) An HTTPS proxy is involved. |
| 14414 | // 3) The HTTPS proxy requests a client certificate. |
| 14415 | // 4) The client supplies an invalid/unacceptable certificate for the |
| 14416 | // proxy. |
| 14417 | // The test is repeated twice, first for connecting to an HTTPS endpoint, |
| 14418 | // then for connecting to an HTTP endpoint. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14419 | TEST_F(HttpNetworkTransactionTest, ClientAuthCertCache_Proxy_Fail) { |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 14420 | session_deps_.proxy_resolution_service = ProxyResolutionService::CreateFixed( |
| 14421 | "https://proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 14422 | BoundTestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14423 | session_deps_.net_log = log.bound().net_log(); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14424 | |
| 14425 | scoped_refptr<SSLCertRequestInfo> cert_request(new SSLCertRequestInfo()); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14426 | cert_request->host_and_port = HostPortPair("proxy", 70); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14427 | |
| 14428 | // See ClientAuthCertCache_Direct_NoFalseStart for the explanation of |
| 14429 | // [ssl_]data[1-3]. Rather than represending the endpoint |
| 14430 | // (www.example.com:443), they represent failures with the HTTPS proxy |
| 14431 | // (proxy:70). |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14432 | SSLSocketDataProvider ssl_data1(ASYNC, ERR_SSL_CLIENT_AUTH_CERT_NEEDED); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14433 | ssl_data1.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14434 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data1); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14435 | StaticSocketDataProvider data1; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14436 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14437 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14438 | SSLSocketDataProvider ssl_data2(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14439 | ssl_data2.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14440 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data2); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14441 | StaticSocketDataProvider data2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14442 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14443 | |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14444 | // TODO(wtc): find out why this unit test doesn't need [ssl_]data3. |
| 14445 | #if 0 |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14446 | SSLSocketDataProvider ssl_data3(ASYNC, ERR_SSL_PROTOCOL_ERROR); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14447 | ssl_data3.cert_request_info = cert_request.get(); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14448 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl_data3); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14449 | StaticSocketDataProvider data3; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14450 | session_deps_.socket_factory->AddSocketDataProvider(&data3); |
[email protected] | 80c75f68 | 2012-05-26 16:22:17 | [diff] [blame] | 14451 | #endif |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14452 | |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14453 | HttpRequestInfo requests[2]; |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14454 | requests[0].url = GURL("https://www.example.com/"); |
| 14455 | requests[0].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14456 | requests[0].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14457 | requests[0].traffic_annotation = |
| 14458 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14459 | |
| 14460 | requests[1].url = GURL("http://www.example.com/"); |
| 14461 | requests[1].method = "GET"; |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 14462 | requests[1].load_flags = LOAD_NORMAL; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14463 | requests[1].traffic_annotation = |
| 14464 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14465 | |
| 14466 | for (size_t i = 0; i < arraysize(requests); ++i) { |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14467 | session_deps_.socket_factory->ResetNextMockIndexes(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14468 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14469 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14470 | |
| 14471 | // Begin the SSL handshake with the proxy. |
[email protected] | 49639fa | 2011-12-20 23:22:41 | [diff] [blame] | 14472 | TestCompletionCallback callback; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14473 | int rv = trans.Start(&requests[i], callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14474 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14475 | |
| 14476 | // Complete the SSL handshake, which should abort due to requiring a |
| 14477 | // client certificate. |
| 14478 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14479 | ASSERT_THAT(rv, IsError(ERR_SSL_CLIENT_AUTH_CERT_NEEDED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14480 | |
| 14481 | // Indicate that no certificate should be supplied. From the perspective |
| 14482 | // of SSLClientCertCache, NULL is just as meaningful as a real |
| 14483 | // certificate, so this is the same as supply a |
| 14484 | // legitimate-but-unacceptable certificate. |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 14485 | rv = trans.RestartWithCertificate(NULL, NULL, callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14486 | ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14487 | |
| 14488 | // Ensure the certificate was added to the client auth cache before |
| 14489 | // allowing the connection to continue restarting. |
| 14490 | scoped_refptr<X509Certificate> client_cert; |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14491 | scoped_refptr<SSLPrivateKey> client_private_key; |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14492 | ASSERT_TRUE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14493 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14494 | ASSERT_FALSE(client_cert); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14495 | // Ensure the certificate was NOT cached for the endpoint. This only |
| 14496 | // applies to HTTPS requests, but is fine to check for HTTP requests. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14497 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14498 | HostPortPair("www.example.com", 443), &client_cert, |
| 14499 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14500 | |
| 14501 | // Restart the handshake. This will consume ssl_data2, which fails, and |
| 14502 | // then consume ssl_data3, which should also fail. The result code is |
| 14503 | // checked against what ssl_data3 should return. |
| 14504 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14505 | ASSERT_THAT(rv, IsError(ERR_PROXY_CONNECTION_FAILED)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14506 | |
| 14507 | // Now that the new handshake has failed, ensure that the client |
| 14508 | // certificate was removed from the client auth cache. |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14509 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14510 | HostPortPair("proxy", 70), &client_cert, &client_private_key)); |
[email protected] | 791879c | 2013-12-17 07:22:41 | [diff] [blame] | 14511 | ASSERT_FALSE(session->ssl_client_auth_cache()->Lookup( |
svaldez | 7872fd0 | 2015-11-19 21:10:54 | [diff] [blame] | 14512 | HostPortPair("www.example.com", 443), &client_cert, |
| 14513 | &client_private_key)); |
[email protected] | 8c40513 | 2011-01-11 22:03:18 | [diff] [blame] | 14514 | } |
| 14515 | } |
| 14516 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14517 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPooling) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14518 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14519 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14520 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14521 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14522 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14523 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14524 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14525 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14526 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14527 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14528 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14529 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14530 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14531 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14532 | spdy::SpdySerializedFrame host1_resp( |
| 14533 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 14534 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14535 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14536 | spdy::SpdySerializedFrame host2_resp( |
| 14537 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 14538 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14539 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14540 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14541 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14542 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14543 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14544 | }; |
| 14545 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14546 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14547 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14548 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14549 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14550 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 14551 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14552 | HttpRequestInfo request1; |
| 14553 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14554 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14555 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14556 | request1.traffic_annotation = |
| 14557 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14558 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14559 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14560 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14561 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14562 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14563 | |
| 14564 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14565 | ASSERT_TRUE(response); |
| 14566 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14567 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14568 | |
| 14569 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14570 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14571 | EXPECT_EQ("hello!", response_data); |
| 14572 | |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14573 | // Preload mail.example.com into HostCache. |
| 14574 | HostPortPair host_port("mail.example.com", 443); |
[email protected] | 5109c195 | 2013-08-20 18:44:10 | [diff] [blame] | 14575 | HostResolver::RequestInfo resolve_info(host_port); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14576 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 14577 | std::unique_ptr<HostResolver::Request> request; |
| 14578 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14579 | &ignored, callback.callback(), |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14580 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14581 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 14582 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14583 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14584 | |
| 14585 | HttpRequestInfo request2; |
| 14586 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14587 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14588 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14589 | request2.traffic_annotation = |
| 14590 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14591 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14592 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14593 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14594 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14595 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14596 | |
| 14597 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14598 | ASSERT_TRUE(response); |
| 14599 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14600 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14601 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14602 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14603 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14604 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14605 | } |
| 14606 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14607 | TEST_F(HttpNetworkTransactionTest, UseIPConnectionPoolingAfterResolution) { |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14608 | // Set up a special HttpNetworkSession with a MockCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14609 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14610 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14611 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14612 | AddSSLSocketData(); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14613 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14614 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14615 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14616 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14617 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14618 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14619 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14620 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14621 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14622 | spdy::SpdySerializedFrame host1_resp( |
| 14623 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 14624 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14625 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14626 | spdy::SpdySerializedFrame host2_resp( |
| 14627 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 14628 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14629 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14630 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14631 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14632 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14633 | MockRead(ASYNC, 0, 6), |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14634 | }; |
| 14635 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14636 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14637 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14638 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 14639 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14640 | |
| 14641 | TestCompletionCallback callback; |
| 14642 | HttpRequestInfo request1; |
| 14643 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 14644 | request1.url = GURL("https://www.example.org/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14645 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14646 | request1.traffic_annotation = |
| 14647 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14648 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14649 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14650 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14651 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14652 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14653 | |
| 14654 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14655 | ASSERT_TRUE(response); |
| 14656 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14657 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14658 | |
| 14659 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14660 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14661 | EXPECT_EQ("hello!", response_data); |
| 14662 | |
| 14663 | HttpRequestInfo request2; |
| 14664 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14665 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14666 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14667 | request2.traffic_annotation = |
| 14668 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 14669 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14670 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14671 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14672 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14673 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14674 | |
| 14675 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 14676 | ASSERT_TRUE(response); |
| 14677 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 14678 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14679 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 14680 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 14681 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14682 | EXPECT_EQ("hello!", response_data); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14683 | } |
| 14684 | |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14685 | // Regression test for https://crbug.com/546991. |
| 14686 | // The server might not be able to serve an IP pooled request, and might send a |
| 14687 | // 421 Misdirected Request response status to indicate this. |
| 14688 | // HttpNetworkTransaction should reset the request and retry without IP pooling. |
| 14689 | TEST_F(HttpNetworkTransactionTest, RetryWithoutConnectionPooling) { |
| 14690 | // Two hosts resolve to the same IP address. |
| 14691 | const std::string ip_addr = "1.2.3.4"; |
| 14692 | IPAddress ip; |
| 14693 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14694 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14695 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14696 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14697 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14698 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14699 | |
| 14700 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14701 | |
| 14702 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14703 | spdy::SpdySerializedFrame req1( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14704 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14705 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14706 | spdy::SpdySerializedFrame req2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14707 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14708 | spdy::SpdySerializedFrame rst( |
| 14709 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14710 | MockWrite writes1[] = { |
| 14711 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14712 | CreateMockWrite(rst, 6), |
| 14713 | }; |
| 14714 | |
| 14715 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14716 | spdy::SpdySerializedFrame resp1( |
| 14717 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14718 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14719 | spdy::SpdyHeaderBlock response_headers; |
| 14720 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 14721 | spdy::SpdySerializedFrame resp2( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14722 | spdy_util_.ConstructSpdyReply(3, std::move(response_headers))); |
| 14723 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14724 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14725 | |
| 14726 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14727 | SequencedSocketData data1(connect1, reads1, writes1); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14728 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14729 | |
| 14730 | AddSSLSocketData(); |
| 14731 | |
| 14732 | // Retry the second request on a second connection. |
| 14733 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14734 | spdy::SpdySerializedFrame req3( |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14735 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14736 | MockWrite writes2[] = { |
| 14737 | CreateMockWrite(req3, 0), |
| 14738 | }; |
| 14739 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14740 | spdy::SpdySerializedFrame resp3( |
| 14741 | spdy_util2.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14742 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14743 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14744 | MockRead(ASYNC, 0, 3)}; |
| 14745 | |
| 14746 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14747 | SequencedSocketData data2(connect2, reads2, writes2); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14748 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14749 | |
| 14750 | AddSSLSocketData(); |
| 14751 | |
| 14752 | // Preload mail.example.org into HostCache. |
| 14753 | HostPortPair host_port("mail.example.org", 443); |
| 14754 | HostResolver::RequestInfo resolve_info(host_port); |
| 14755 | AddressList ignored; |
| 14756 | std::unique_ptr<HostResolver::Request> request; |
| 14757 | TestCompletionCallback callback; |
| 14758 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14759 | &ignored, callback.callback(), |
| 14760 | &request, NetLogWithSource()); |
| 14761 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14762 | rv = callback.WaitForResult(); |
| 14763 | EXPECT_THAT(rv, IsOk()); |
| 14764 | |
| 14765 | HttpRequestInfo request1; |
| 14766 | request1.method = "GET"; |
| 14767 | request1.url = GURL("https://www.example.org/"); |
| 14768 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14769 | request1.traffic_annotation = |
| 14770 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14771 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14772 | |
| 14773 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14774 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14775 | rv = callback.WaitForResult(); |
| 14776 | EXPECT_THAT(rv, IsOk()); |
| 14777 | |
| 14778 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14779 | ASSERT_TRUE(response); |
| 14780 | ASSERT_TRUE(response->headers); |
| 14781 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14782 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14783 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14784 | std::string response_data; |
| 14785 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14786 | EXPECT_EQ("hello!", response_data); |
| 14787 | |
| 14788 | HttpRequestInfo request2; |
| 14789 | request2.method = "GET"; |
| 14790 | request2.url = GURL("https://mail.example.org/"); |
| 14791 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14792 | request2.traffic_annotation = |
| 14793 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14794 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14795 | |
| 14796 | BoundTestNetLog log; |
| 14797 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14798 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14799 | rv = callback.WaitForResult(); |
| 14800 | EXPECT_THAT(rv, IsOk()); |
| 14801 | |
| 14802 | response = trans2.GetResponseInfo(); |
| 14803 | ASSERT_TRUE(response); |
| 14804 | ASSERT_TRUE(response->headers); |
| 14805 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14806 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14807 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14808 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14809 | EXPECT_EQ("hello!", response_data); |
| 14810 | |
| 14811 | TestNetLogEntry::List entries; |
| 14812 | log.GetEntries(&entries); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14813 | ExpectLogContainsSomewhere( |
| 14814 | entries, 0, NetLogEventType::HTTP_TRANSACTION_RESTART_MISDIRECTED_REQUEST, |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14815 | NetLogEventPhase::NONE); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14816 | } |
| 14817 | |
| 14818 | // Test that HTTP 421 responses are properly returned to the caller if received |
| 14819 | // on the retry as well. HttpNetworkTransaction should not infinite loop or lose |
| 14820 | // portions of the response. |
| 14821 | TEST_F(HttpNetworkTransactionTest, ReturnHTTP421OnRetry) { |
| 14822 | // Two hosts resolve to the same IP address. |
| 14823 | const std::string ip_addr = "1.2.3.4"; |
| 14824 | IPAddress ip; |
| 14825 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
| 14826 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 14827 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14828 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14829 | session_deps_.host_resolver->rules()->AddRule("www.example.org", ip_addr); |
| 14830 | session_deps_.host_resolver->rules()->AddRule("mail.example.org", ip_addr); |
| 14831 | |
| 14832 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 14833 | |
| 14834 | // Two requests on the first connection. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14835 | spdy::SpdySerializedFrame req1( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14836 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
| 14837 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14838 | spdy::SpdySerializedFrame req2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14839 | spdy_util_.ConstructSpdyGet("https://mail.example.org", 3, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14840 | spdy::SpdySerializedFrame rst( |
| 14841 | spdy_util_.ConstructSpdyRstStream(3, spdy::ERROR_CODE_CANCEL)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14842 | MockWrite writes1[] = { |
| 14843 | CreateMockWrite(req1, 0), CreateMockWrite(req2, 3), |
| 14844 | CreateMockWrite(rst, 6), |
| 14845 | }; |
| 14846 | |
| 14847 | // The first one succeeds, the second gets error 421 Misdirected Request. |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14848 | spdy::SpdySerializedFrame resp1( |
| 14849 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
| 14850 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
| 14851 | spdy::SpdyHeaderBlock response_headers; |
| 14852 | response_headers[spdy::kHttp2StatusHeader] = "421"; |
| 14853 | spdy::SpdySerializedFrame resp2( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14854 | spdy_util_.ConstructSpdyReply(3, response_headers.Clone())); |
| 14855 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
| 14856 | CreateMockRead(resp2, 4), MockRead(ASYNC, 0, 5)}; |
| 14857 | |
| 14858 | MockConnect connect1(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14859 | SequencedSocketData data1(connect1, reads1, writes1); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14860 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 14861 | |
| 14862 | AddSSLSocketData(); |
| 14863 | |
| 14864 | // Retry the second request on a second connection. It returns 421 Misdirected |
| 14865 | // Retry again. |
| 14866 | SpdyTestUtil spdy_util2; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14867 | spdy::SpdySerializedFrame req3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14868 | spdy_util2.ConstructSpdyGet("https://mail.example.org", 1, LOWEST)); |
| 14869 | MockWrite writes2[] = { |
| 14870 | CreateMockWrite(req3, 0), |
| 14871 | }; |
| 14872 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14873 | spdy::SpdySerializedFrame resp3( |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14874 | spdy_util2.ConstructSpdyReply(1, std::move(response_headers))); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14875 | spdy::SpdySerializedFrame body3(spdy_util2.ConstructSpdyDataFrame(1, true)); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14876 | MockRead reads2[] = {CreateMockRead(resp3, 1), CreateMockRead(body3, 2), |
| 14877 | MockRead(ASYNC, 0, 3)}; |
| 14878 | |
| 14879 | MockConnect connect2(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 14880 | SequencedSocketData data2(connect2, reads2, writes2); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14881 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
| 14882 | |
| 14883 | AddSSLSocketData(); |
| 14884 | |
| 14885 | // Preload mail.example.org into HostCache. |
| 14886 | HostPortPair host_port("mail.example.org", 443); |
| 14887 | HostResolver::RequestInfo resolve_info(host_port); |
| 14888 | AddressList ignored; |
| 14889 | std::unique_ptr<HostResolver::Request> request; |
| 14890 | TestCompletionCallback callback; |
| 14891 | int rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 14892 | &ignored, callback.callback(), |
| 14893 | &request, NetLogWithSource()); |
| 14894 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14895 | rv = callback.WaitForResult(); |
| 14896 | EXPECT_THAT(rv, IsOk()); |
| 14897 | |
| 14898 | HttpRequestInfo request1; |
| 14899 | request1.method = "GET"; |
| 14900 | request1.url = GURL("https://www.example.org/"); |
| 14901 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14902 | request1.traffic_annotation = |
| 14903 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14904 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 14905 | |
| 14906 | rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
| 14907 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14908 | rv = callback.WaitForResult(); |
| 14909 | EXPECT_THAT(rv, IsOk()); |
| 14910 | |
| 14911 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
| 14912 | ASSERT_TRUE(response); |
| 14913 | ASSERT_TRUE(response->headers); |
| 14914 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
| 14915 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14916 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14917 | std::string response_data; |
| 14918 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
| 14919 | EXPECT_EQ("hello!", response_data); |
| 14920 | |
| 14921 | HttpRequestInfo request2; |
| 14922 | request2.method = "GET"; |
| 14923 | request2.url = GURL("https://mail.example.org/"); |
| 14924 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 14925 | request2.traffic_annotation = |
| 14926 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
davidben | ce688ae | 2017-05-04 15:12:59 | [diff] [blame] | 14927 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 14928 | |
| 14929 | BoundTestNetLog log; |
| 14930 | rv = trans2.Start(&request2, callback.callback(), log.bound()); |
| 14931 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 14932 | rv = callback.WaitForResult(); |
| 14933 | EXPECT_THAT(rv, IsOk()); |
| 14934 | |
| 14935 | // After a retry, the 421 Misdirected Request is reported back up to the |
| 14936 | // caller. |
| 14937 | response = trans2.GetResponseInfo(); |
| 14938 | ASSERT_TRUE(response); |
| 14939 | ASSERT_TRUE(response->headers); |
| 14940 | EXPECT_EQ("HTTP/1.1 421", response->headers->GetStatusLine()); |
| 14941 | EXPECT_TRUE(response->was_fetched_via_spdy); |
| 14942 | EXPECT_TRUE(response->was_alpn_negotiated); |
| 14943 | EXPECT_TRUE(response->ssl_info.cert); |
| 14944 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
| 14945 | EXPECT_EQ("hello!", response_data); |
bnc | 8016c1f | 2017-03-31 02:11:29 | [diff] [blame] | 14946 | } |
| 14947 | |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14948 | class OneTimeCachingHostResolver : public MockHostResolverBase { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14949 | public: |
| 14950 | explicit OneTimeCachingHostResolver(const HostPortPair& host_port) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14951 | : MockHostResolverBase(/* use_caching = */ true), host_port_(host_port) {} |
Chris Watkins | 7a41d355 | 2017-12-01 02:13:27 | [diff] [blame] | 14952 | ~OneTimeCachingHostResolver() override = default; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14953 | |
dcheng | b03027d | 2014-10-21 12:00:20 | [diff] [blame] | 14954 | int ResolveFromCache(const RequestInfo& info, |
| 14955 | AddressList* addresses, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 14956 | const NetLogWithSource& net_log) override { |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14957 | int rv = MockHostResolverBase::ResolveFromCache(info, addresses, net_log); |
[email protected] | 95a214c | 2011-08-04 21:50:40 | [diff] [blame] | 14958 | if (rv == OK && info.host_port_pair().Equals(host_port_)) |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 14959 | GetHostCache()->clear(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14960 | return rv; |
| 14961 | } |
| 14962 | |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14963 | private: |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14964 | const HostPortPair host_port_; |
| 14965 | }; |
| 14966 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 14967 | TEST_F(HttpNetworkTransactionTest, |
mmenke | 5c64213 | 2015-06-02 16:05:13 | [diff] [blame] | 14968 | UseIPConnectionPoolingWithHostCacheExpiration) { |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14969 | // Set up a special HttpNetworkSession with a OneTimeCachingHostResolver. |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 14970 | session_deps_.host_resolver = std::make_unique<OneTimeCachingHostResolver>( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14971 | HostPortPair("mail.example.com", 443)); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 14972 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14973 | |
bnc | 032658ba | 2016-09-26 18:17:15 | [diff] [blame] | 14974 | AddSSLSocketData(); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14975 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14976 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 14977 | spdy_util_.ConstructSpdyGet("https://www.example.org", 1, LOWEST)); |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 14978 | spdy_util_.UpdateWithStreamDestruction(1); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14979 | spdy::SpdySerializedFrame host2_req( |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 14980 | spdy_util_.ConstructSpdyGet("https://mail.example.com", 3, LOWEST)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14981 | MockWrite spdy_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14982 | CreateMockWrite(host1_req, 0), CreateMockWrite(host2_req, 3), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14983 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14984 | spdy::SpdySerializedFrame host1_resp( |
| 14985 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 14986 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14987 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 14988 | spdy::SpdySerializedFrame host2_resp( |
| 14989 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 14990 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14991 | spdy_util_.ConstructSpdyDataFrame(3, true)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14992 | MockRead spdy_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 14993 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
| 14994 | CreateMockRead(host2_resp, 4), CreateMockRead(host2_resp_body, 5), |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 14995 | MockRead(ASYNC, 0, 6), |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 14996 | }; |
| 14997 | |
eroman | 36d84e5443 | 2016-03-17 03:23:02 | [diff] [blame] | 14998 | IPEndPoint peer_addr(IPAddress::IPv4Localhost(), 443); |
[email protected] | d2b5f09 | 2012-06-08 23:55:02 | [diff] [blame] | 14999 | MockConnect connect(ASYNC, OK, peer_addr); |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15000 | SequencedSocketData spdy_data(connect, spdy_reads, spdy_writes); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15001 | session_deps_.socket_factory->AddSocketDataProvider(&spdy_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15002 | |
[email protected] | aa22b24 | 2011-11-16 18:58:29 | [diff] [blame] | 15003 | TestCompletionCallback callback; |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15004 | HttpRequestInfo request1; |
| 15005 | request1.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15006 | request1.url = GURL("https://www.example.org/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15007 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15008 | request1.traffic_annotation = |
| 15009 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15010 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15011 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15012 | int rv = trans1.Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15013 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15014 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15015 | |
| 15016 | const HttpResponseInfo* response = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15017 | ASSERT_TRUE(response); |
| 15018 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15019 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15020 | |
| 15021 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15022 | ASSERT_THAT(ReadTransaction(&trans1, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15023 | EXPECT_EQ("hello!", response_data); |
| 15024 | |
| 15025 | // Preload cache entries into HostCache. |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15026 | HostResolver::RequestInfo resolve_info(HostPortPair("mail.example.com", 443)); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15027 | AddressList ignored; |
maksim.sisov | 31452af | 2016-07-27 06:38:10 | [diff] [blame] | 15028 | std::unique_ptr<HostResolver::Request> request; |
bnc | 6dcd819 | 2017-05-25 20:11:50 | [diff] [blame] | 15029 | rv = session_deps_.host_resolver->Resolve(resolve_info, DEFAULT_PRIORITY, |
| 15030 | &ignored, callback.callback(), |
| 15031 | &request, NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15032 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 6e78dfb | 2011-07-28 21:34:47 | [diff] [blame] | 15033 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15034 | EXPECT_THAT(rv, IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15035 | |
| 15036 | HttpRequestInfo request2; |
| 15037 | request2.method = "GET"; |
bnc | a4d611d | 2016-09-22 19:55:37 | [diff] [blame] | 15038 | request2.url = GURL("https://mail.example.com/"); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15039 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15040 | request2.traffic_annotation = |
| 15041 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15042 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15043 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15044 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15045 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15046 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15047 | |
| 15048 | response = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15049 | ASSERT_TRUE(response); |
| 15050 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15051 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15052 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15053 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15054 | ASSERT_THAT(ReadTransaction(&trans2, &response_data), IsOk()); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15055 | EXPECT_EQ("hello!", response_data); |
[email protected] | e3ceb68 | 2011-06-28 23:55:46 | [diff] [blame] | 15056 | } |
| 15057 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15058 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttp) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15059 | const std::string https_url = "https://www.example.org:8080/"; |
| 15060 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15061 | |
| 15062 | // SPDY GET for HTTPS URL |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15063 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15064 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15065 | |
| 15066 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15067 | CreateMockWrite(req1, 0), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15068 | }; |
| 15069 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15070 | spdy::SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15071 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15072 | MockRead reads1[] = {CreateMockRead(resp1, 1), CreateMockRead(body1, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15073 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3)}; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15074 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15075 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15076 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15077 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15078 | |
| 15079 | // HTTP GET for the HTTP URL |
| 15080 | MockWrite writes2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15081 | MockWrite(ASYNC, 0, |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15082 | "GET / HTTP/1.1\r\n" |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15083 | "Host: www.example.org:8080\r\n" |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15084 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15085 | }; |
| 15086 | |
| 15087 | MockRead reads2[] = { |
rch | 8e6c6c4 | 2015-05-01 14:05:13 | [diff] [blame] | 15088 | MockRead(ASYNC, 1, "HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\n"), |
| 15089 | MockRead(ASYNC, 2, "hello"), |
| 15090 | MockRead(ASYNC, OK, 3), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15091 | }; |
| 15092 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15093 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15094 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15095 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15096 | ssl.next_proto = kProtoHTTP2; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15097 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15098 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
| 15099 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15100 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15101 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15102 | |
| 15103 | // Start the first transaction to set up the SpdySession |
| 15104 | HttpRequestInfo request1; |
| 15105 | request1.method = "GET"; |
| 15106 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15107 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15108 | request1.traffic_annotation = |
| 15109 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15110 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15111 | TestCompletionCallback callback1; |
| 15112 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15113 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15114 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15115 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15116 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15117 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15118 | |
| 15119 | // Now, start the HTTP request |
| 15120 | HttpRequestInfo request2; |
| 15121 | request2.method = "GET"; |
| 15122 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15123 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15124 | request2.traffic_annotation = |
| 15125 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15126 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15127 | TestCompletionCallback callback2; |
| 15128 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15129 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15130 | base::RunLoop().RunUntilIdle(); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15131 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15132 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15133 | EXPECT_FALSE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15134 | } |
| 15135 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15136 | // Alternative service requires HTTP/2 (or SPDY), but HTTP/1.1 is negotiated |
| 15137 | // with the alternative server. That connection should not be used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15138 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceNotOnHttp11) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15139 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 15140 | HostPortPair alternative("www.example.org", 444); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15141 | |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15142 | // Negotiate HTTP/1.1 with alternative. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15143 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15144 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15145 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15146 | |
| 15147 | // No data should be read from the alternative, because HTTP/1.1 is |
| 15148 | // negotiated. |
| 15149 | StaticSocketDataProvider data; |
| 15150 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15151 | |
| 15152 | // 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] | 15153 | // negotiated. In order to test this, a failed connection to the server is |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15154 | // mocked. This way the request relies on the alternate Job. |
| 15155 | StaticSocketDataProvider data_refused; |
| 15156 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 15157 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 15158 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15159 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15160 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15161 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15162 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15163 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15164 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15165 | http_server_properties->SetHttp2AlternativeService( |
| 15166 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15167 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15168 | HttpRequestInfo request; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15169 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15170 | request.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15171 | request.url = GURL("https://www.example.org:443"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15172 | request.traffic_annotation = |
| 15173 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15174 | TestCompletionCallback callback; |
| 15175 | |
| 15176 | // HTTP/2 (or SPDY) is required for alternative service, if HTTP/1.1 is |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15177 | // negotiated, the alternate Job should fail with ERR_ALPN_NEGOTIATION_FAILED. |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15178 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15179 | EXPECT_THAT(callback.GetResult(rv), IsError(ERR_ALPN_NEGOTIATION_FAILED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15180 | } |
| 15181 | |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15182 | // 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] | 15183 | // server, and an alternate one to the alternative server. If the former |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15184 | // succeeds, the request should succeed, even if the latter fails because |
| 15185 | // HTTP/1.1 is negotiated which is insufficient for alternative service. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15186 | TEST_F(HttpNetworkTransactionTest, FailedAlternativeServiceIsNotUserVisible) { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15187 | url::SchemeHostPort server("https", "www.example.org", 443); |
| 15188 | HostPortPair alternative("www.example.org", 444); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15189 | |
| 15190 | // Negotiate HTTP/1.1 with alternative. |
| 15191 | SSLSocketDataProvider alternative_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15192 | alternative_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15193 | session_deps_.socket_factory->AddSSLSocketDataProvider(&alternative_ssl); |
| 15194 | |
| 15195 | // No data should be read from the alternative, because HTTP/1.1 is |
| 15196 | // negotiated. |
| 15197 | StaticSocketDataProvider data; |
| 15198 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15199 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15200 | // Negotiate HTTP/1.1 with server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15201 | SSLSocketDataProvider origin_ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15202 | origin_ssl.next_proto = kProtoHTTP11; |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15203 | session_deps_.socket_factory->AddSSLSocketDataProvider(&origin_ssl); |
| 15204 | |
| 15205 | MockWrite http_writes[] = { |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15206 | MockWrite("GET / HTTP/1.1\r\n" |
| 15207 | "Host: www.example.org\r\n" |
| 15208 | "Connection: keep-alive\r\n\r\n"), |
| 15209 | MockWrite("GET /second HTTP/1.1\r\n" |
| 15210 | "Host: www.example.org\r\n" |
| 15211 | "Connection: keep-alive\r\n\r\n"), |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15212 | }; |
| 15213 | |
| 15214 | MockRead http_reads[] = { |
| 15215 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15216 | MockRead("Content-Type: text/html\r\n"), |
| 15217 | MockRead("Content-Length: 6\r\n\r\n"), |
| 15218 | MockRead("foobar"), |
| 15219 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15220 | MockRead("Content-Type: text/html\r\n"), |
| 15221 | MockRead("Content-Length: 7\r\n\r\n"), |
| 15222 | MockRead("another"), |
| 15223 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15224 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15225 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15226 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15227 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15228 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15229 | HttpServerProperties* http_server_properties = |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15230 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15231 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15232 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15233 | http_server_properties->SetHttp2AlternativeService( |
| 15234 | server, alternative_service, expiration); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15235 | |
| 15236 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
| 15237 | HttpRequestInfo request1; |
| 15238 | request1.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15239 | request1.url = GURL("https://www.example.org:443"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15240 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15241 | request1.traffic_annotation = |
| 15242 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15243 | TestCompletionCallback callback1; |
| 15244 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15245 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15246 | rv = callback1.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15247 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15248 | |
| 15249 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15250 | ASSERT_TRUE(response1); |
| 15251 | ASSERT_TRUE(response1->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15252 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
| 15253 | |
| 15254 | std::string response_data1; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15255 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15256 | EXPECT_EQ("foobar", response_data1); |
| 15257 | |
| 15258 | // Alternative should be marked as broken, because HTTP/1.1 is not sufficient |
| 15259 | // for alternative service. |
| 15260 | EXPECT_TRUE( |
| 15261 | http_server_properties->IsAlternativeServiceBroken(alternative_service)); |
| 15262 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15263 | // Since |alternative_service| is broken, a second transaction to server |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15264 | // should not start an alternate Job. It should pool to existing connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15265 | // to server. |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15266 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
| 15267 | HttpRequestInfo request2; |
| 15268 | request2.method = "GET"; |
bnc | 8bef8da2 | 2016-05-30 01:28:25 | [diff] [blame] | 15269 | request2.url = GURL("https://www.example.org:443/second"); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15270 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15271 | request2.traffic_annotation = |
| 15272 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15273 | TestCompletionCallback callback2; |
| 15274 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15275 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15276 | rv = callback2.GetResult(rv); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15277 | EXPECT_THAT(rv, IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15278 | |
| 15279 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15280 | ASSERT_TRUE(response2); |
| 15281 | ASSERT_TRUE(response2->headers); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15282 | EXPECT_EQ("HTTP/1.1 200 OK", response2->headers->GetStatusLine()); |
| 15283 | |
| 15284 | std::string response_data2; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15285 | ASSERT_THAT(ReadTransaction(&trans2, &response_data2), IsOk()); |
bnc | 40448a53 | 2015-05-11 19:13:14 | [diff] [blame] | 15286 | EXPECT_EQ("another", response_data2); |
| 15287 | } |
| 15288 | |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15289 | // Alternative service requires HTTP/2 (or SPDY), but there is already a |
| 15290 | // HTTP/1.1 socket open to the alternative server. That socket should not be |
| 15291 | // used. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15292 | TEST_F(HttpNetworkTransactionTest, AlternativeServiceShouldNotPoolToHttp11) { |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15293 | url::SchemeHostPort server("https", "origin.example.org", 443); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15294 | HostPortPair alternative("alternative.example.org", 443); |
| 15295 | std::string origin_url = "https://origin.example.org:443"; |
| 15296 | std::string alternative_url = "https://alternative.example.org:443"; |
| 15297 | |
| 15298 | // Negotiate HTTP/1.1 with alternative.example.org. |
| 15299 | SSLSocketDataProvider ssl(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15300 | ssl.next_proto = kProtoHTTP11; |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15301 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 15302 | |
| 15303 | // HTTP/1.1 data for |request1| and |request2|. |
| 15304 | MockWrite http_writes[] = { |
| 15305 | MockWrite( |
| 15306 | "GET / HTTP/1.1\r\n" |
| 15307 | "Host: alternative.example.org\r\n" |
| 15308 | "Connection: keep-alive\r\n\r\n"), |
| 15309 | MockWrite( |
| 15310 | "GET / HTTP/1.1\r\n" |
| 15311 | "Host: alternative.example.org\r\n" |
| 15312 | "Connection: keep-alive\r\n\r\n"), |
| 15313 | }; |
| 15314 | |
| 15315 | MockRead http_reads[] = { |
| 15316 | MockRead( |
| 15317 | "HTTP/1.1 200 OK\r\n" |
| 15318 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 15319 | "Content-Length: 40\r\n\r\n" |
| 15320 | "first HTTP/1.1 response from alternative"), |
| 15321 | MockRead( |
| 15322 | "HTTP/1.1 200 OK\r\n" |
| 15323 | "Content-Type: text/html; charset=iso-8859-1\r\n" |
| 15324 | "Content-Length: 41\r\n\r\n" |
| 15325 | "second HTTP/1.1 response from alternative"), |
| 15326 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15327 | StaticSocketDataProvider http_data(http_reads, http_writes); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15328 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15329 | |
| 15330 | // This test documents that an alternate Job should not pool to an already |
| 15331 | // existing HTTP/1.1 connection. In order to test this, a failed connection |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15332 | // to the server is mocked. This way |request2| relies on the alternate Job. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15333 | StaticSocketDataProvider data_refused; |
| 15334 | data_refused.set_connect_data(MockConnect(ASYNC, ERR_CONNECTION_REFUSED)); |
| 15335 | session_deps_.socket_factory->AddSocketDataProvider(&data_refused); |
| 15336 | |
zhongyi | 3d4a55e7 | 2016-04-22 20:36:46 | [diff] [blame] | 15337 | // Set up alternative service for server. |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15338 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 525e175a | 2016-06-20 12:36:40 | [diff] [blame] | 15339 | HttpServerProperties* http_server_properties = |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15340 | session->http_server_properties(); |
bnc | 3472afd | 2016-11-17 15:27:21 | [diff] [blame] | 15341 | AlternativeService alternative_service(kProtoHTTP2, alternative); |
bnc | 7dc7e1b4 | 2015-07-28 14:43:12 | [diff] [blame] | 15342 | base::Time expiration = base::Time::Now() + base::TimeDelta::FromDays(1); |
zhongyi | e537a00 | 2017-06-27 16:48:21 | [diff] [blame] | 15343 | http_server_properties->SetHttp2AlternativeService( |
| 15344 | server, alternative_service, expiration); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15345 | |
| 15346 | // First transaction to alternative to open an HTTP/1.1 socket. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15347 | HttpRequestInfo request1; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15348 | HttpNetworkTransaction trans1(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15349 | request1.method = "GET"; |
| 15350 | request1.url = GURL(alternative_url); |
| 15351 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15352 | request1.traffic_annotation = |
| 15353 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15354 | TestCompletionCallback callback1; |
| 15355 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15356 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15357 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15358 | const HttpResponseInfo* response1 = trans1.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15359 | ASSERT_TRUE(response1); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15360 | ASSERT_TRUE(response1->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15361 | EXPECT_EQ("HTTP/1.1 200 OK", response1->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15362 | EXPECT_TRUE(response1->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15363 | EXPECT_FALSE(response1->was_fetched_via_spdy); |
| 15364 | std::string response_data1; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15365 | ASSERT_THAT(ReadTransaction(&trans1, &response_data1), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15366 | EXPECT_EQ("first HTTP/1.1 response from alternative", response_data1); |
| 15367 | |
| 15368 | // Request for origin.example.org, which has an alternative service. This |
| 15369 | // will start two Jobs: the alternative looks for connections to pool to, |
| 15370 | // 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] | 15371 | // open other connections to alternative server. The Job to server fails, so |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15372 | // this request fails. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15373 | HttpRequestInfo request2; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15374 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15375 | request2.method = "GET"; |
| 15376 | request2.url = GURL(origin_url); |
| 15377 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15378 | request2.traffic_annotation = |
| 15379 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15380 | TestCompletionCallback callback2; |
| 15381 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15382 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15383 | EXPECT_THAT(callback2.GetResult(rv), IsError(ERR_CONNECTION_REFUSED)); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15384 | |
| 15385 | // Another transaction to alternative. This is to test that the HTTP/1.1 |
| 15386 | // socket is still open and in the pool. |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15387 | HttpRequestInfo request3; |
krasin | c06a72a | 2016-12-21 03:42:46 | [diff] [blame] | 15388 | HttpNetworkTransaction trans3(DEFAULT_PRIORITY, session.get()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15389 | request3.method = "GET"; |
| 15390 | request3.url = GURL(alternative_url); |
| 15391 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15392 | request3.traffic_annotation = |
| 15393 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15394 | TestCompletionCallback callback3; |
| 15395 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15396 | rv = trans3.Start(&request3, callback3.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15397 | EXPECT_THAT(callback3.GetResult(rv), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15398 | const HttpResponseInfo* response3 = trans3.GetResponseInfo(); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15399 | ASSERT_TRUE(response3); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15400 | ASSERT_TRUE(response3->headers); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15401 | EXPECT_EQ("HTTP/1.1 200 OK", response3->headers->GetStatusLine()); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15402 | EXPECT_TRUE(response3->was_alpn_negotiated); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15403 | EXPECT_FALSE(response3->was_fetched_via_spdy); |
| 15404 | std::string response_data3; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15405 | ASSERT_THAT(ReadTransaction(&trans3, &response_data3), IsOk()); |
bnc | 5452e2a | 2015-05-08 16:27:42 | [diff] [blame] | 15406 | EXPECT_EQ("second HTTP/1.1 response from alternative", response_data3); |
| 15407 | } |
| 15408 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15409 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionForHttpOverTunnel) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15410 | const std::string https_url = "https://www.example.org:8080/"; |
| 15411 | const std::string http_url = "http://www.example.org:8080/"; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15412 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15413 | // Separate SPDY util instance for naked and wrapped requests. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15414 | SpdyTestUtil spdy_util_wrapped; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15415 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15416 | // SPDY GET for HTTPS URL (through CONNECT tunnel) |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15417 | const HostPortPair host_port_pair("www.example.org", 8080); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15418 | spdy::SpdySerializedFrame connect( |
lgarron | a91df87f | 2014-12-05 00:51:34 | [diff] [blame] | 15419 | spdy_util_.ConstructSpdyConnect(NULL, 0, 1, LOWEST, host_port_pair)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15420 | spdy::SpdySerializedFrame req1( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15421 | spdy_util_wrapped.ConstructSpdyGet(https_url.c_str(), 1, LOWEST)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15422 | spdy::SpdySerializedFrame wrapped_req1( |
[email protected] | 23e48228 | 2013-06-14 16:08:02 | [diff] [blame] | 15423 | spdy_util_.ConstructWrappedSpdyFrame(req1, 1)); |
[email protected] | 601e03f1 | 2014-04-06 16:26:39 | [diff] [blame] | 15424 | |
| 15425 | // SPDY GET for HTTP URL (through the proxy, but not the tunnel). |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15426 | spdy::SpdyHeaderBlock req2_block; |
| 15427 | req2_block[spdy::kHttp2MethodHeader] = "GET"; |
| 15428 | req2_block[spdy::kHttp2AuthorityHeader] = "www.example.org:8080"; |
| 15429 | req2_block[spdy::kHttp2SchemeHeader] = "http"; |
| 15430 | req2_block[spdy::kHttp2PathHeader] = "/"; |
| 15431 | spdy::SpdySerializedFrame req2( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15432 | spdy_util_.ConstructSpdyHeaders(3, std::move(req2_block), MEDIUM, true)); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15433 | |
| 15434 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15435 | CreateMockWrite(connect, 0), CreateMockWrite(wrapped_req1, 2), |
| 15436 | CreateMockWrite(req2, 6), |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15437 | }; |
| 15438 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15439 | spdy::SpdySerializedFrame conn_resp( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15440 | spdy_util_.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15441 | spdy::SpdySerializedFrame resp1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15442 | spdy_util_wrapped.ConstructSpdyGetReply(nullptr, 0, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15443 | spdy::SpdySerializedFrame body1( |
| 15444 | spdy_util_wrapped.ConstructSpdyDataFrame(1, true)); |
| 15445 | spdy::SpdySerializedFrame wrapped_resp1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15446 | spdy_util_wrapped.ConstructWrappedSpdyFrame(resp1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15447 | spdy::SpdySerializedFrame wrapped_body1( |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15448 | spdy_util_wrapped.ConstructWrappedSpdyFrame(body1, 1)); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15449 | spdy::SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 3)); |
| 15450 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(3, true)); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15451 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15452 | CreateMockRead(conn_resp, 1), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15453 | MockRead(ASYNC, ERR_IO_PENDING, 3), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15454 | CreateMockRead(wrapped_resp1, 4), |
| 15455 | CreateMockRead(wrapped_body1, 5), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15456 | MockRead(ASYNC, ERR_IO_PENDING, 7), |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15457 | CreateMockRead(resp2, 8), |
| 15458 | CreateMockRead(body2, 9), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15459 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 10), |
| 15460 | }; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15461 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15462 | SequencedSocketData data1(reads1, writes1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15463 | MockConnect connect_data1(ASYNC, OK); |
[email protected] | dd54bd8 | 2012-07-19 23:44:57 | [diff] [blame] | 15464 | data1.set_connect_data(connect_data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15465 | |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 15466 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15467 | ProxyResolutionService::CreateFixedFromPacResult( |
| 15468 | "HTTPS proxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
vishal.b | 62985ca9 | 2015-04-17 08:45:51 | [diff] [blame] | 15469 | TestNetLog log; |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15470 | session_deps_.net_log = &log; |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15471 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15472 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15473 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15474 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15475 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15476 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15477 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15478 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15479 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15480 | |
| 15481 | // Start the first transaction to set up the SpdySession |
| 15482 | HttpRequestInfo request1; |
| 15483 | request1.method = "GET"; |
| 15484 | request1.url = GURL(https_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15485 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15486 | request1.traffic_annotation = |
| 15487 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15488 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15489 | TestCompletionCallback callback1; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15490 | int rv = trans1.Start(&request1, callback1.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15491 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15492 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15493 | data1.RunUntilPaused(); |
| 15494 | base::RunLoop().RunUntilIdle(); |
| 15495 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15496 | EXPECT_THAT(callback1.GetResult(rv), IsOk()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15497 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15498 | |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 15499 | LoadTimingInfo load_timing_info1; |
| 15500 | EXPECT_TRUE(trans1.GetLoadTimingInfo(&load_timing_info1)); |
| 15501 | TestLoadTimingNotReusedWithPac(load_timing_info1, |
| 15502 | CONNECT_TIMING_HAS_SSL_TIMES); |
| 15503 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15504 | // Now, start the HTTP request. |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15505 | HttpRequestInfo request2; |
| 15506 | request2.method = "GET"; |
| 15507 | request2.url = GURL(http_url); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15508 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15509 | request2.traffic_annotation = |
| 15510 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15511 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15512 | TestCompletionCallback callback2; |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15513 | rv = trans2.Start(&request2, callback2.callback(), NetLogWithSource()); |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15514 | |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15515 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15516 | data1.RunUntilPaused(); |
| 15517 | base::RunLoop().RunUntilIdle(); |
| 15518 | data1.Resume(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15519 | EXPECT_THAT(callback2.GetResult(rv), IsOk()); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15520 | |
[email protected] | 8450d72 | 2012-07-02 19:14:04 | [diff] [blame] | 15521 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
[email protected] | f6c63db5 | 2013-02-02 00:35:22 | [diff] [blame] | 15522 | |
| 15523 | LoadTimingInfo load_timing_info2; |
| 15524 | EXPECT_TRUE(trans2.GetLoadTimingInfo(&load_timing_info2)); |
| 15525 | // The established SPDY sessions is considered reused by the HTTP request. |
| 15526 | TestLoadTimingReusedWithPac(load_timing_info2); |
| 15527 | // HTTP requests over a SPDY session should have a different connection |
| 15528 | // socket_log_id than requests over a tunnel. |
| 15529 | 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] | 15530 | } |
| 15531 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15532 | // Test that in the case where we have a SPDY session to a SPDY proxy |
| 15533 | // that we do not pool other origins that resolve to the same IP when |
| 15534 | // the certificate does not match the new origin. |
| 15535 | // http://crbug.com/134690 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15536 | TEST_F(HttpNetworkTransactionTest, DoNotUseSpdySessionIfCertDoesNotMatch) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15537 | const std::string url1 = "http://www.example.org/"; |
| 15538 | const std::string url2 = "https://news.example.org/"; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15539 | const std::string ip_addr = "1.2.3.4"; |
| 15540 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15541 | // Second SpdyTestUtil instance for the second socket. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15542 | SpdyTestUtil spdy_util_secure; |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15543 | |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15544 | // SPDY GET for HTTP URL (through SPDY proxy) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15545 | spdy::SpdyHeaderBlock headers( |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15546 | spdy_util_.ConstructGetHeaderBlockForProxy("http://www.example.org/")); |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15547 | spdy::SpdySerializedFrame req1( |
bnc | 4233140 | 2016-07-25 13:36:15 | [diff] [blame] | 15548 | spdy_util_.ConstructSpdyHeaders(1, std::move(headers), LOWEST, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15549 | |
| 15550 | MockWrite writes1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15551 | CreateMockWrite(req1, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15552 | }; |
| 15553 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15554 | spdy::SpdySerializedFrame resp1(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15555 | spdy::SpdySerializedFrame body1(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15556 | MockRead reads1[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15557 | MockRead(ASYNC, ERR_IO_PENDING, 1), CreateMockRead(resp1, 2), |
| 15558 | CreateMockRead(body1, 3), MockRead(ASYNC, OK, 4), // EOF |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15559 | }; |
| 15560 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15561 | SequencedSocketData data1(reads1, writes1); |
martijn | fe9636e | 2016-02-06 14:33:32 | [diff] [blame] | 15562 | IPAddress ip; |
martijn | 654c8c4 | 2016-02-10 22:10:59 | [diff] [blame] | 15563 | ASSERT_TRUE(ip.AssignFromIPLiteral(ip_addr)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15564 | IPEndPoint peer_addr = IPEndPoint(ip, 443); |
| 15565 | MockConnect connect_data1(ASYNC, OK, peer_addr); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15566 | data1.set_connect_data(connect_data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15567 | |
| 15568 | // SPDY GET for HTTPS URL (direct) |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15569 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15570 | spdy_util_secure.ConstructSpdyGet(url2.c_str(), 1, MEDIUM)); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15571 | |
| 15572 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15573 | CreateMockWrite(req2, 0), |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15574 | }; |
| 15575 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15576 | spdy::SpdySerializedFrame resp2( |
| 15577 | spdy_util_secure.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15578 | spdy::SpdySerializedFrame body2( |
| 15579 | spdy_util_secure.ConstructSpdyDataFrame(1, true)); |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15580 | MockRead reads2[] = {CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15581 | MockRead(ASYNC, OK, 3)}; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15582 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15583 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15584 | MockConnect connect_data2(ASYNC, OK); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15585 | data2.set_connect_data(connect_data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15586 | |
| 15587 | // Set up a proxy config that sends HTTP requests to a proxy, and |
| 15588 | // all others direct. |
| 15589 | ProxyConfig proxy_config; |
| 15590 | proxy_config.proxy_rules().ParseFromString("http=https://proxy:443"); |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 15591 | session_deps_.proxy_resolution_service = |
| 15592 | std::make_unique<ProxyResolutionService>( |
| 15593 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 15594 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
| 15595 | nullptr, nullptr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15596 | |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15597 | SSLSocketDataProvider ssl1(ASYNC, OK); // to the proxy |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15598 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15599 | // Load a valid cert. Note, that this does not need to |
| 15600 | // be valid for proxy because the MockSSLClientSocket does |
| 15601 | // not actually verify it. But SpdySession will use this |
| 15602 | // to see if it is valid for the new origin |
Ryan Sleevi | 4f83209 | 2017-11-21 23:25:49 | [diff] [blame] | 15603 | ssl1.ssl_info.cert = |
| 15604 | ImportCertFromFile(GetTestCertsDirectory(), "ok_cert.pem"); |
| 15605 | ASSERT_TRUE(ssl1.ssl_info.cert); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15606 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15607 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15608 | |
| 15609 | SSLSocketDataProvider ssl2(ASYNC, OK); // to the server |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15610 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15611 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15612 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15613 | |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15614 | session_deps_.host_resolver = std::make_unique<MockCachingHostResolver>(); |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15615 | session_deps_.host_resolver->rules()->AddRule("news.example.org", ip_addr); |
[email protected] | bb88e1d3 | 2013-05-03 23:11:07 | [diff] [blame] | 15616 | session_deps_.host_resolver->rules()->AddRule("proxy", ip_addr); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15617 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15618 | std::unique_ptr<HttpNetworkSession> session = CreateSession(&session_deps_); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15619 | |
| 15620 | // Start the first transaction to set up the SpdySession |
| 15621 | HttpRequestInfo request1; |
| 15622 | request1.method = "GET"; |
| 15623 | request1.url = GURL(url1); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15624 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15625 | request1.traffic_annotation = |
| 15626 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15627 | HttpNetworkTransaction trans1(LOWEST, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15628 | TestCompletionCallback callback1; |
| 15629 | ASSERT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15630 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
mmenke | 666a6fea | 2015-12-19 04:16:33 | [diff] [blame] | 15631 | // This pause is a hack to avoid running into https://crbug.com/497228. |
| 15632 | data1.RunUntilPaused(); |
| 15633 | base::RunLoop().RunUntilIdle(); |
| 15634 | data1.Resume(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15635 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15636 | EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15637 | EXPECT_TRUE(trans1.GetResponseInfo()->was_fetched_via_spdy); |
| 15638 | |
| 15639 | // Now, start the HTTP request |
| 15640 | HttpRequestInfo request2; |
| 15641 | request2.method = "GET"; |
| 15642 | request2.url = GURL(url2); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15643 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15644 | request2.traffic_annotation = |
| 15645 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15646 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15647 | TestCompletionCallback callback2; |
| 15648 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15649 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
fdoray | 92e35a7 | 2016-06-10 15:54:55 | [diff] [blame] | 15650 | base::RunLoop().RunUntilIdle(); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15651 | |
| 15652 | ASSERT_TRUE(callback2.have_result()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15653 | EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 2d88e7d | 2012-07-19 17:55:17 | [diff] [blame] | 15654 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15655 | } |
| 15656 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15657 | // Test to verify that a failed socket read (due to an ERR_CONNECTION_CLOSED |
| 15658 | // error) in SPDY session, removes the socket from pool and closes the SPDY |
| 15659 | // session. Verify that new url's from the same HttpNetworkSession (and a new |
| 15660 | // SpdySession) do work. http://crbug.com/224701 |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15661 | TEST_F(HttpNetworkTransactionTest, ErrorSocketNotConnected) { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15662 | const std::string https_url = "https://www.example.org/"; |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15663 | |
| 15664 | MockRead reads1[] = { |
| 15665 | MockRead(SYNCHRONOUS, ERR_CONNECTION_CLOSED, 0) |
| 15666 | }; |
| 15667 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15668 | SequencedSocketData data1(reads1, base::span<MockWrite>()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15669 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15670 | spdy::SpdySerializedFrame req2( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15671 | spdy_util_.ConstructSpdyGet(https_url.c_str(), 1, MEDIUM)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15672 | MockWrite writes2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15673 | CreateMockWrite(req2, 0), |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15674 | }; |
| 15675 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15676 | spdy::SpdySerializedFrame resp2(spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15677 | spdy::SpdySerializedFrame body2(spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15678 | MockRead reads2[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15679 | CreateMockRead(resp2, 1), CreateMockRead(body2, 2), |
| 15680 | MockRead(ASYNC, OK, 3) // EOF |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15681 | }; |
| 15682 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15683 | SequencedSocketData data2(reads2, writes2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15684 | |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15685 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15686 | ssl1.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15687 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15688 | session_deps_.socket_factory->AddSocketDataProvider(&data1); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15689 | |
| 15690 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15691 | ssl2.next_proto = kProtoHTTP2; |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15692 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15693 | session_deps_.socket_factory->AddSocketDataProvider(&data2); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15694 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15695 | std::unique_ptr<HttpNetworkSession> session( |
mmenke | 11eb515 | 2015-06-09 14:50:50 | [diff] [blame] | 15696 | SpdySessionDependencies::SpdyCreateSession(&session_deps_)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15697 | |
| 15698 | // Start the first transaction to set up the SpdySession and verify that |
| 15699 | // connection was closed. |
| 15700 | HttpRequestInfo request1; |
| 15701 | request1.method = "GET"; |
| 15702 | request1.url = GURL(https_url); |
| 15703 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15704 | request1.traffic_annotation = |
| 15705 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15706 | HttpNetworkTransaction trans1(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15707 | TestCompletionCallback callback1; |
| 15708 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15709 | trans1.Start(&request1, callback1.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15710 | EXPECT_THAT(callback1.WaitForResult(), IsError(ERR_CONNECTION_CLOSED)); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15711 | |
| 15712 | // Now, start the second request and make sure it succeeds. |
| 15713 | HttpRequestInfo request2; |
| 15714 | request2.method = "GET"; |
| 15715 | request2.url = GURL(https_url); |
| 15716 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15717 | request2.traffic_annotation = |
| 15718 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 9049948 | 2013-06-01 00:39:50 | [diff] [blame] | 15719 | HttpNetworkTransaction trans2(MEDIUM, session.get()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15720 | TestCompletionCallback callback2; |
| 15721 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15722 | trans2.Start(&request2, callback2.callback(), NetLogWithSource())); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15723 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15724 | ASSERT_THAT(callback2.WaitForResult(), IsOk()); |
[email protected] | 85f9734 | 2013-04-17 06:12:24 | [diff] [blame] | 15725 | EXPECT_TRUE(trans2.GetResponseInfo()->was_fetched_via_spdy); |
| 15726 | } |
| 15727 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15728 | TEST_F(HttpNetworkTransactionTest, CloseIdleSpdySessionToOpenNewOne) { |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15729 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 15730 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15731 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 15732 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 15733 | |
| 15734 | // Use two different hosts with different IPs so they don't get pooled. |
| 15735 | session_deps_.host_resolver->rules()->AddRule("www.a.com", "10.0.0.1"); |
| 15736 | session_deps_.host_resolver->rules()->AddRule("www.b.com", "10.0.0.2"); |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15737 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15738 | |
| 15739 | SSLSocketDataProvider ssl1(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15740 | ssl1.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15741 | SSLSocketDataProvider ssl2(ASYNC, OK); |
bnc | 3cf2a59 | 2016-08-11 14:48:36 | [diff] [blame] | 15742 | ssl2.next_proto = kProtoHTTP2; |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15743 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl1); |
| 15744 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl2); |
| 15745 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15746 | spdy::SpdySerializedFrame host1_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15747 | spdy_util_.ConstructSpdyGet("https://www.a.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15748 | MockWrite spdy1_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15749 | CreateMockWrite(host1_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15750 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15751 | spdy::SpdySerializedFrame host1_resp( |
| 15752 | spdy_util_.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15753 | spdy::SpdySerializedFrame host1_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15754 | spdy_util_.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15755 | MockRead spdy1_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15756 | CreateMockRead(host1_resp, 1), CreateMockRead(host1_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15757 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15758 | }; |
| 15759 | |
rdsmith | ebb50aa | 2015-11-12 03:44:38 | [diff] [blame] | 15760 | // Use a separate test instance for the separate SpdySession that will be |
| 15761 | // created. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15762 | SpdyTestUtil spdy_util_2; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15763 | SequencedSocketData spdy1_data(spdy1_reads, spdy1_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 15764 | session_deps_.socket_factory->AddSocketDataProvider(&spdy1_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15765 | |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15766 | spdy::SpdySerializedFrame host2_req( |
bnc | 38dcd39 | 2016-02-09 23:19:49 | [diff] [blame] | 15767 | spdy_util_2.ConstructSpdyGet("https://www.b.com", 1, DEFAULT_PRIORITY)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15768 | MockWrite spdy2_writes[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15769 | CreateMockWrite(host2_req, 0), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15770 | }; |
Ryan Hamilton | 0239aac | 2018-05-19 00:03:13 | [diff] [blame] | 15771 | spdy::SpdySerializedFrame host2_resp( |
| 15772 | spdy_util_2.ConstructSpdyGetReply(NULL, 0, 1)); |
| 15773 | spdy::SpdySerializedFrame host2_resp_body( |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15774 | spdy_util_2.ConstructSpdyDataFrame(1, true)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15775 | MockRead spdy2_reads[] = { |
bnc | df80d44fd | 2016-07-15 20:27:41 | [diff] [blame] | 15776 | CreateMockRead(host2_resp, 1), CreateMockRead(host2_resp_body, 2), |
mmenke | e2401192 | 2015-12-17 22:12:59 | [diff] [blame] | 15777 | MockRead(SYNCHRONOUS, ERR_IO_PENDING, 3), |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15778 | }; |
| 15779 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15780 | SequencedSocketData spdy2_data(spdy2_reads, spdy2_writes); |
Bence Béky | 53a5aef | 2018-03-29 21:54:12 | [diff] [blame] | 15781 | session_deps_.socket_factory->AddSocketDataProvider(&spdy2_data); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15782 | |
| 15783 | MockWrite http_write[] = { |
| 15784 | MockWrite("GET / HTTP/1.1\r\n" |
| 15785 | "Host: www.a.com\r\n" |
| 15786 | "Connection: keep-alive\r\n\r\n"), |
| 15787 | }; |
| 15788 | |
| 15789 | MockRead http_read[] = { |
| 15790 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 15791 | MockRead("Content-Type: text/html; charset=iso-8859-1\r\n"), |
| 15792 | MockRead("Content-Length: 6\r\n\r\n"), |
| 15793 | MockRead("hello!"), |
| 15794 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15795 | StaticSocketDataProvider http_data(http_read, http_write); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15796 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 15797 | |
| 15798 | HostPortPair host_port_pair_a("www.a.com", 443); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15799 | SpdySessionKey spdy_session_key_a(host_port_pair_a, ProxyServer::Direct(), |
| 15800 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15801 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15802 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15803 | |
| 15804 | TestCompletionCallback callback; |
| 15805 | HttpRequestInfo request1; |
| 15806 | request1.method = "GET"; |
| 15807 | request1.url = GURL("https://www.a.com/"); |
| 15808 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15809 | request1.traffic_annotation = |
| 15810 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15811 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15812 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15813 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15814 | int rv = trans->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15815 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15816 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15817 | |
| 15818 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15819 | ASSERT_TRUE(response); |
| 15820 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15821 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15822 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15823 | EXPECT_TRUE(response->was_alpn_negotiated); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15824 | |
| 15825 | std::string response_data; |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15826 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15827 | EXPECT_EQ("hello!", response_data); |
| 15828 | trans.reset(); |
| 15829 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15830 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15831 | |
| 15832 | HostPortPair host_port_pair_b("www.b.com", 443); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15833 | SpdySessionKey spdy_session_key_b(host_port_pair_b, ProxyServer::Direct(), |
| 15834 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15835 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15836 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15837 | HttpRequestInfo request2; |
| 15838 | request2.method = "GET"; |
| 15839 | request2.url = GURL("https://www.b.com/"); |
| 15840 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15841 | request2.traffic_annotation = |
| 15842 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15843 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15844 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15845 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15846 | rv = trans->Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15847 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15848 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15849 | |
| 15850 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15851 | ASSERT_TRUE(response); |
| 15852 | ASSERT_TRUE(response->headers); |
bnc | 84e7fb5 | 2015-12-02 11:50:02 | [diff] [blame] | 15853 | EXPECT_EQ("HTTP/1.1 200", response->headers->GetStatusLine()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15854 | EXPECT_TRUE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15855 | EXPECT_TRUE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15856 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15857 | EXPECT_EQ("hello!", response_data); |
| 15858 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15859 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15860 | EXPECT_TRUE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15861 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15862 | |
| 15863 | HostPortPair host_port_pair_a1("www.a.com", 80); |
Paul Jensen | a457017a | 2018-01-19 23:52:04 | [diff] [blame] | 15864 | SpdySessionKey spdy_session_key_a1(host_port_pair_a1, ProxyServer::Direct(), |
| 15865 | PRIVACY_MODE_DISABLED, SocketTag()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15866 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15867 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a1)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15868 | HttpRequestInfo request3; |
| 15869 | request3.method = "GET"; |
| 15870 | request3.url = GURL("http://www.a.com/"); |
| 15871 | request3.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15872 | request3.traffic_annotation = |
| 15873 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 15874 | trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 15875 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15876 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15877 | rv = trans->Start(&request3, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15878 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 15879 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15880 | |
| 15881 | response = trans->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 15882 | ASSERT_TRUE(response); |
| 15883 | ASSERT_TRUE(response->headers); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15884 | EXPECT_EQ("HTTP/1.1 200 OK", response->headers->GetStatusLine()); |
| 15885 | EXPECT_FALSE(response->was_fetched_via_spdy); |
bnc | 94c9284 | 2016-09-21 15:22:52 | [diff] [blame] | 15886 | EXPECT_FALSE(response->was_alpn_negotiated); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15887 | ASSERT_THAT(ReadTransaction(trans.get(), &response_data), IsOk()); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15888 | EXPECT_EQ("hello!", response_data); |
| 15889 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15890 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_a)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15891 | EXPECT_FALSE( |
[email protected] | 41d64e8 | 2013-07-03 22:44:26 | [diff] [blame] | 15892 | HasSpdySession(session->spdy_session_pool(), spdy_session_key_b)); |
[email protected] | 483fa20 | 2013-05-14 01:07:03 | [diff] [blame] | 15893 | } |
| 15894 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15895 | TEST_F(HttpNetworkTransactionTest, HttpSyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15896 | HttpRequestInfo request; |
| 15897 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15898 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15899 | request.traffic_annotation = |
| 15900 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15901 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15902 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15903 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15904 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15905 | MockConnect mock_connect(SYNCHRONOUS, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15906 | StaticSocketDataProvider data; |
| 15907 | data.set_connect_data(mock_connect); |
| 15908 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15909 | |
| 15910 | TestCompletionCallback callback; |
| 15911 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15912 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15913 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15914 | |
| 15915 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15916 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15917 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15918 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 15919 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15920 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15921 | |
| 15922 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15923 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15924 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15925 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15926 | |
| 15927 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15928 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15929 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15930 | } |
| 15931 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15932 | TEST_F(HttpNetworkTransactionTest, HttpAsyncConnectError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15933 | HttpRequestInfo request; |
| 15934 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15935 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15936 | request.traffic_annotation = |
| 15937 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15938 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15939 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15940 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15941 | |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15942 | MockConnect mock_connect(ASYNC, ERR_NAME_NOT_RESOLVED); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15943 | StaticSocketDataProvider data; |
| 15944 | data.set_connect_data(mock_connect); |
| 15945 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15946 | |
| 15947 | TestCompletionCallback callback; |
| 15948 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15949 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15950 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15951 | |
| 15952 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15953 | EXPECT_THAT(rv, IsError(ERR_NAME_NOT_RESOLVED)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15954 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15955 | // We don't care whether this succeeds or fails, but it shouldn't crash. |
| 15956 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15957 | trans.GetFullRequestHeaders(&request_headers); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15958 | |
| 15959 | ConnectionAttempts attempts; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15960 | trans.GetConnectionAttempts(&attempts); |
ttuttle | 1f2d7e9 | 2015-04-28 16:17:47 | [diff] [blame] | 15961 | ASSERT_EQ(1u, attempts.size()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15962 | EXPECT_THAT(attempts[0].result, IsError(ERR_NAME_NOT_RESOLVED)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15963 | |
| 15964 | IPEndPoint endpoint; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15965 | EXPECT_FALSE(trans.GetRemoteEndpoint(&endpoint)); |
ttuttle | d9dbc65 | 2015-09-29 20:00:59 | [diff] [blame] | 15966 | EXPECT_TRUE(endpoint.address().empty()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15967 | } |
| 15968 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 15969 | TEST_F(HttpNetworkTransactionTest, HttpSyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15970 | HttpRequestInfo request; |
| 15971 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 15972 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 15973 | request.traffic_annotation = |
| 15974 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15975 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 15976 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15977 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15978 | |
| 15979 | MockWrite data_writes[] = { |
| 15980 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 15981 | }; |
| 15982 | MockRead data_reads[] = { |
| 15983 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 15984 | }; |
| 15985 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 15986 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15987 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 15988 | |
| 15989 | TestCompletionCallback callback; |
| 15990 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 15991 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15992 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15993 | |
| 15994 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 15995 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15996 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15997 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 15998 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 15999 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16000 | } |
| 16001 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16002 | TEST_F(HttpNetworkTransactionTest, HttpAsyncWriteError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16003 | HttpRequestInfo request; |
| 16004 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16005 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16006 | request.traffic_annotation = |
| 16007 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16008 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16009 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16010 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16011 | |
| 16012 | MockWrite data_writes[] = { |
| 16013 | MockWrite(ASYNC, ERR_CONNECTION_RESET), |
| 16014 | }; |
| 16015 | MockRead data_reads[] = { |
| 16016 | MockRead(SYNCHRONOUS, ERR_UNEXPECTED), // Should not be reached. |
| 16017 | }; |
| 16018 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16019 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16020 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16021 | |
| 16022 | TestCompletionCallback callback; |
| 16023 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16024 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16025 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16026 | |
| 16027 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16028 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16029 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16030 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16031 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16032 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16033 | } |
| 16034 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16035 | TEST_F(HttpNetworkTransactionTest, HttpSyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16036 | HttpRequestInfo request; |
| 16037 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16038 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16039 | request.traffic_annotation = |
| 16040 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16041 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16042 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16043 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16044 | |
| 16045 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16046 | MockWrite( |
| 16047 | "GET / HTTP/1.1\r\n" |
| 16048 | "Host: www.example.org\r\n" |
| 16049 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16050 | }; |
| 16051 | MockRead data_reads[] = { |
| 16052 | MockRead(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16053 | }; |
| 16054 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16055 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16056 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16057 | |
| 16058 | TestCompletionCallback callback; |
| 16059 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16060 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16061 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16062 | |
| 16063 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16064 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16065 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16066 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16067 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16068 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16069 | } |
| 16070 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16071 | TEST_F(HttpNetworkTransactionTest, HttpAsyncReadError) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16072 | HttpRequestInfo request; |
| 16073 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16074 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16075 | request.traffic_annotation = |
| 16076 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16077 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16078 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16079 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16080 | |
| 16081 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16082 | MockWrite( |
| 16083 | "GET / HTTP/1.1\r\n" |
| 16084 | "Host: www.example.org\r\n" |
| 16085 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16086 | }; |
| 16087 | MockRead data_reads[] = { |
| 16088 | MockRead(ASYNC, ERR_CONNECTION_RESET), |
| 16089 | }; |
| 16090 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16091 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16092 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16093 | |
| 16094 | TestCompletionCallback callback; |
| 16095 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16096 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16097 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16098 | |
| 16099 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16100 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16101 | |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16102 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16103 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16104 | EXPECT_TRUE(request_headers.HasHeader("Host")); |
| 16105 | } |
| 16106 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16107 | TEST_F(HttpNetworkTransactionTest, GetFullRequestHeadersIncludesExtraHeader) { |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16108 | HttpRequestInfo request; |
| 16109 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16110 | request.url = GURL("http://www.example.org/"); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16111 | request.extra_headers.SetHeader("X-Foo", "bar"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16112 | request.traffic_annotation = |
| 16113 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16114 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16115 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16116 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16117 | |
| 16118 | MockWrite data_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16119 | MockWrite( |
| 16120 | "GET / HTTP/1.1\r\n" |
| 16121 | "Host: www.example.org\r\n" |
| 16122 | "Connection: keep-alive\r\n" |
| 16123 | "X-Foo: bar\r\n\r\n"), |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16124 | }; |
| 16125 | MockRead data_reads[] = { |
| 16126 | MockRead("HTTP/1.1 200 OK\r\n" |
| 16127 | "Content-Length: 5\r\n\r\n" |
| 16128 | "hello"), |
| 16129 | MockRead(ASYNC, ERR_UNEXPECTED), |
| 16130 | }; |
| 16131 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16132 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16133 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16134 | |
| 16135 | TestCompletionCallback callback; |
| 16136 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16137 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16138 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16139 | |
| 16140 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16141 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16142 | |
| 16143 | HttpRequestHeaders request_headers; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16144 | EXPECT_TRUE(trans.GetFullRequestHeaders(&request_headers)); |
[email protected] | 79e1fd6 | 2013-06-20 06:50:04 | [diff] [blame] | 16145 | std::string foo; |
| 16146 | EXPECT_TRUE(request_headers.GetHeader("X-Foo", &foo)); |
| 16147 | EXPECT_EQ("bar", foo); |
| 16148 | } |
| 16149 | |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16150 | // Tests that when a used socket is returned to the SSL socket pool, it's closed |
| 16151 | // if the transport socket pool is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16152 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16153 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16154 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16155 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16156 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16157 | |
| 16158 | // Set up SSL request. |
| 16159 | |
| 16160 | HttpRequestInfo ssl_request; |
| 16161 | ssl_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16162 | ssl_request.url = GURL("https://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16163 | ssl_request.traffic_annotation = |
| 16164 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16165 | |
| 16166 | MockWrite ssl_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16167 | MockWrite( |
| 16168 | "GET / HTTP/1.1\r\n" |
| 16169 | "Host: www.example.org\r\n" |
| 16170 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16171 | }; |
| 16172 | MockRead ssl_reads[] = { |
| 16173 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16174 | MockRead("Content-Length: 11\r\n\r\n"), |
| 16175 | MockRead("hello world"), |
| 16176 | MockRead(SYNCHRONOUS, OK), |
| 16177 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16178 | StaticSocketDataProvider ssl_data(ssl_reads, ssl_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16179 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16180 | |
| 16181 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16182 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16183 | |
| 16184 | // Set up HTTP request. |
| 16185 | |
| 16186 | HttpRequestInfo http_request; |
| 16187 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16188 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16189 | http_request.traffic_annotation = |
| 16190 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16191 | |
| 16192 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16193 | MockWrite( |
| 16194 | "GET / HTTP/1.1\r\n" |
| 16195 | "Host: www.example.org\r\n" |
| 16196 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16197 | }; |
| 16198 | MockRead http_reads[] = { |
| 16199 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16200 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16201 | MockRead("falafel"), |
| 16202 | MockRead(SYNCHRONOUS, OK), |
| 16203 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16204 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16205 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16206 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16207 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16208 | |
| 16209 | // Start the SSL request. |
| 16210 | TestCompletionCallback ssl_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16211 | HttpNetworkTransaction ssl_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16212 | ASSERT_EQ(ERR_IO_PENDING, |
| 16213 | ssl_trans.Start(&ssl_request, ssl_callback.callback(), |
| 16214 | NetLogWithSource())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16215 | |
| 16216 | // Start the HTTP request. Pool should stall. |
| 16217 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16218 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16219 | ASSERT_EQ(ERR_IO_PENDING, |
| 16220 | http_trans.Start(&http_request, http_callback.callback(), |
| 16221 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16222 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16223 | |
| 16224 | // Wait for response from SSL request. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16225 | ASSERT_THAT(ssl_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16226 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16227 | ASSERT_THAT(ReadTransaction(&ssl_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16228 | EXPECT_EQ("hello world", response_data); |
| 16229 | |
| 16230 | // The SSL socket should automatically be closed, so the HTTP request can |
| 16231 | // start. |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16232 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
| 16233 | ASSERT_FALSE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16234 | |
| 16235 | // The HTTP request can now complete. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16236 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16237 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16238 | EXPECT_EQ("falafel", response_data); |
| 16239 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16240 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16241 | } |
| 16242 | |
| 16243 | // Tests that when a SSL connection is established but there's no corresponding |
| 16244 | // request that needs it, the new socket is closed if the transport socket pool |
| 16245 | // is stalled on the global socket limit. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16246 | TEST_F(HttpNetworkTransactionTest, CloseSSLSocketOnIdleForHttpRequest2) { |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16247 | ClientSocketPoolManager::set_max_sockets_per_group( |
| 16248 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16249 | ClientSocketPoolManager::set_max_sockets_per_pool( |
| 16250 | HttpNetworkSession::NORMAL_SOCKET_POOL, 1); |
| 16251 | |
| 16252 | // Set up an ssl request. |
| 16253 | |
| 16254 | HttpRequestInfo ssl_request; |
| 16255 | ssl_request.method = "GET"; |
| 16256 | ssl_request.url = GURL("https://www.foopy.com/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16257 | ssl_request.traffic_annotation = |
| 16258 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16259 | |
| 16260 | // No data will be sent on the SSL socket. |
| 16261 | StaticSocketDataProvider ssl_data; |
| 16262 | session_deps_.socket_factory->AddSocketDataProvider(&ssl_data); |
| 16263 | |
| 16264 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16265 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16266 | |
| 16267 | // Set up HTTP request. |
| 16268 | |
| 16269 | HttpRequestInfo http_request; |
| 16270 | http_request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16271 | http_request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16272 | http_request.traffic_annotation = |
| 16273 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16274 | |
| 16275 | MockWrite http_writes[] = { |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16276 | MockWrite( |
| 16277 | "GET / HTTP/1.1\r\n" |
| 16278 | "Host: www.example.org\r\n" |
| 16279 | "Connection: keep-alive\r\n\r\n"), |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16280 | }; |
| 16281 | MockRead http_reads[] = { |
| 16282 | MockRead("HTTP/1.1 200 OK\r\n"), |
| 16283 | MockRead("Content-Length: 7\r\n\r\n"), |
| 16284 | MockRead("falafel"), |
| 16285 | MockRead(SYNCHRONOUS, OK), |
| 16286 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16287 | StaticSocketDataProvider http_data(http_reads, http_writes); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16288 | session_deps_.socket_factory->AddSocketDataProvider(&http_data); |
| 16289 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16290 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16291 | |
| 16292 | // Preconnect an SSL socket. A preconnect is needed because connect jobs are |
| 16293 | // cancelled when a normal transaction is cancelled. |
ttuttle | 859dc7a | 2015-04-23 19:42:29 | [diff] [blame] | 16294 | HttpStreamFactory* http_stream_factory = session->http_stream_factory(); |
nharper | 8cdb0fb | 2016-04-22 21:34:59 | [diff] [blame] | 16295 | http_stream_factory->PreconnectStreams(1, ssl_request); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16296 | EXPECT_EQ(0, GetIdleSocketCountInSSLSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16297 | |
| 16298 | // Start the HTTP request. Pool should stall. |
| 16299 | TestCompletionCallback http_callback; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16300 | HttpNetworkTransaction http_trans(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16301 | ASSERT_EQ(ERR_IO_PENDING, |
| 16302 | http_trans.Start(&http_request, http_callback.callback(), |
| 16303 | NetLogWithSource())); |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16304 | EXPECT_TRUE(IsTransportSocketPoolStalled(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16305 | |
| 16306 | // The SSL connection will automatically be closed once the connection is |
| 16307 | // established, to let the HTTP request start. |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16308 | ASSERT_THAT(http_callback.WaitForResult(), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16309 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16310 | ASSERT_THAT(ReadTransaction(&http_trans, &response_data), IsOk()); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16311 | EXPECT_EQ("falafel", response_data); |
| 16312 | |
dcheng | 48459ac2 | 2014-08-26 00:46:41 | [diff] [blame] | 16313 | EXPECT_EQ(1, GetIdleSocketCountInTransportSocketPool(session.get())); |
[email protected] | 043b68c8 | 2013-08-22 23:41:52 | [diff] [blame] | 16314 | } |
| 16315 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16316 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16317 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16318 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16319 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16320 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16321 | |
| 16322 | HttpRequestInfo request; |
| 16323 | request.method = "POST"; |
| 16324 | request.url = GURL("http://www.foo.com/"); |
| 16325 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16326 | request.traffic_annotation = |
| 16327 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16328 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16329 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16330 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16331 | // Send headers successfully, but get an error while sending the body. |
| 16332 | MockWrite data_writes[] = { |
| 16333 | MockWrite("POST / HTTP/1.1\r\n" |
| 16334 | "Host: www.foo.com\r\n" |
| 16335 | "Connection: keep-alive\r\n" |
| 16336 | "Content-Length: 3\r\n\r\n"), |
| 16337 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16338 | }; |
| 16339 | |
| 16340 | MockRead data_reads[] = { |
| 16341 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16342 | MockRead("hello world"), |
| 16343 | MockRead(SYNCHRONOUS, OK), |
| 16344 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16345 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16346 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16347 | |
| 16348 | TestCompletionCallback callback; |
| 16349 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16350 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16351 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16352 | |
| 16353 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16354 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16355 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16356 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16357 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16358 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16359 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16360 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16361 | |
| 16362 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16363 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16364 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16365 | EXPECT_EQ("hello world", response_data); |
| 16366 | } |
| 16367 | |
| 16368 | // This test makes sure the retry logic doesn't trigger when reading an error |
| 16369 | // response from a server that rejected a POST with a CONNECTION_RESET. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16370 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16371 | PostReadsErrorResponseAfterResetOnReusedSocket) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16372 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16373 | MockWrite data_writes[] = { |
| 16374 | MockWrite("GET / HTTP/1.1\r\n" |
| 16375 | "Host: www.foo.com\r\n" |
| 16376 | "Connection: keep-alive\r\n\r\n"), |
| 16377 | MockWrite("POST / HTTP/1.1\r\n" |
| 16378 | "Host: www.foo.com\r\n" |
| 16379 | "Connection: keep-alive\r\n" |
| 16380 | "Content-Length: 3\r\n\r\n"), |
| 16381 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16382 | }; |
| 16383 | |
| 16384 | MockRead data_reads[] = { |
| 16385 | MockRead("HTTP/1.1 200 Peachy\r\n" |
| 16386 | "Content-Length: 14\r\n\r\n"), |
| 16387 | MockRead("first response"), |
| 16388 | MockRead("HTTP/1.1 400 Not OK\r\n" |
| 16389 | "Content-Length: 15\r\n\r\n"), |
| 16390 | MockRead("second response"), |
| 16391 | MockRead(SYNCHRONOUS, OK), |
| 16392 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16393 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16394 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16395 | |
| 16396 | TestCompletionCallback callback; |
| 16397 | HttpRequestInfo request1; |
| 16398 | request1.method = "GET"; |
| 16399 | request1.url = GURL("http://www.foo.com/"); |
| 16400 | request1.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16401 | request1.traffic_annotation = |
| 16402 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16403 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16404 | auto trans1 = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16405 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16406 | int rv = trans1->Start(&request1, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16407 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16408 | |
| 16409 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16410 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16411 | |
| 16412 | const HttpResponseInfo* response1 = trans1->GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16413 | ASSERT_TRUE(response1); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16414 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16415 | EXPECT_TRUE(response1->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16416 | EXPECT_EQ("HTTP/1.1 200 Peachy", response1->headers->GetStatusLine()); |
| 16417 | |
| 16418 | std::string response_data1; |
| 16419 | rv = ReadTransaction(trans1.get(), &response_data1); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16420 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16421 | EXPECT_EQ("first response", response_data1); |
| 16422 | // Delete the transaction to release the socket back into the socket pool. |
| 16423 | trans1.reset(); |
| 16424 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16425 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16426 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16427 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16428 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16429 | |
| 16430 | HttpRequestInfo request2; |
| 16431 | request2.method = "POST"; |
| 16432 | request2.url = GURL("http://www.foo.com/"); |
| 16433 | request2.upload_data_stream = &upload_data_stream; |
| 16434 | request2.load_flags = 0; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16435 | request2.traffic_annotation = |
| 16436 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16437 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16438 | HttpNetworkTransaction trans2(DEFAULT_PRIORITY, session.get()); |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16439 | rv = trans2.Start(&request2, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16440 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16441 | |
| 16442 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16443 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16444 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16445 | const HttpResponseInfo* response2 = trans2.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16446 | ASSERT_TRUE(response2); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16447 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16448 | EXPECT_TRUE(response2->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16449 | EXPECT_EQ("HTTP/1.1 400 Not OK", response2->headers->GetStatusLine()); |
| 16450 | |
| 16451 | std::string response_data2; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16452 | rv = ReadTransaction(&trans2, &response_data2); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16453 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16454 | EXPECT_EQ("second response", response_data2); |
| 16455 | } |
| 16456 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16457 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16458 | PostReadsErrorResponseAfterResetPartialBodySent) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16459 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16460 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16461 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16462 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16463 | |
| 16464 | HttpRequestInfo request; |
| 16465 | request.method = "POST"; |
| 16466 | request.url = GURL("http://www.foo.com/"); |
| 16467 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16468 | request.traffic_annotation = |
| 16469 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16470 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16471 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16472 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16473 | // Send headers successfully, but get an error while sending the body. |
| 16474 | MockWrite data_writes[] = { |
| 16475 | MockWrite("POST / HTTP/1.1\r\n" |
| 16476 | "Host: www.foo.com\r\n" |
| 16477 | "Connection: keep-alive\r\n" |
| 16478 | "Content-Length: 3\r\n\r\n" |
| 16479 | "fo"), |
| 16480 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16481 | }; |
| 16482 | |
| 16483 | MockRead data_reads[] = { |
| 16484 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16485 | MockRead("hello world"), |
| 16486 | MockRead(SYNCHRONOUS, OK), |
| 16487 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16488 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16489 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16490 | |
| 16491 | TestCompletionCallback callback; |
| 16492 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16493 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16494 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16495 | |
| 16496 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16497 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16498 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16499 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16500 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16501 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16502 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16503 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16504 | |
| 16505 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16506 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16507 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16508 | EXPECT_EQ("hello world", response_data); |
| 16509 | } |
| 16510 | |
| 16511 | // This tests the more common case than the previous test, where headers and |
| 16512 | // body are not merged into a single request. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16513 | TEST_F(HttpNetworkTransactionTest, ChunkedPostReadsErrorResponseAfterReset) { |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16514 | ChunkedUploadDataStream upload_data_stream(0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16515 | |
| 16516 | HttpRequestInfo request; |
| 16517 | request.method = "POST"; |
| 16518 | request.url = GURL("http://www.foo.com/"); |
| 16519 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16520 | request.traffic_annotation = |
| 16521 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16522 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16523 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16524 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16525 | // Send headers successfully, but get an error while sending the body. |
| 16526 | MockWrite data_writes[] = { |
| 16527 | MockWrite("POST / HTTP/1.1\r\n" |
| 16528 | "Host: www.foo.com\r\n" |
| 16529 | "Connection: keep-alive\r\n" |
| 16530 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 16531 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16532 | }; |
| 16533 | |
| 16534 | MockRead data_reads[] = { |
| 16535 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16536 | MockRead("hello world"), |
| 16537 | MockRead(SYNCHRONOUS, OK), |
| 16538 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16539 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16540 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16541 | |
| 16542 | TestCompletionCallback callback; |
| 16543 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16544 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16545 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16546 | // Make sure the headers are sent before adding a chunk. This ensures that |
| 16547 | // they can't be merged with the body in a single send. Not currently |
| 16548 | // necessary since a chunked body is never merged with headers, but this makes |
| 16549 | // the test more future proof. |
| 16550 | base::RunLoop().RunUntilIdle(); |
| 16551 | |
mmenke | cbc2b71 | 2014-10-09 20:29:07 | [diff] [blame] | 16552 | upload_data_stream.AppendData("last chunk", 10, true); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16553 | |
| 16554 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16555 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16556 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16557 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16558 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16559 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16560 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16561 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16562 | |
| 16563 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16564 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16565 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16566 | EXPECT_EQ("hello world", response_data); |
| 16567 | } |
| 16568 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16569 | TEST_F(HttpNetworkTransactionTest, PostReadsErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16570 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16571 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16572 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16573 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16574 | |
| 16575 | HttpRequestInfo request; |
| 16576 | request.method = "POST"; |
| 16577 | request.url = GURL("http://www.foo.com/"); |
| 16578 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16579 | request.traffic_annotation = |
| 16580 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16581 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16582 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16583 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16584 | |
| 16585 | MockWrite data_writes[] = { |
| 16586 | MockWrite("POST / HTTP/1.1\r\n" |
| 16587 | "Host: www.foo.com\r\n" |
| 16588 | "Connection: keep-alive\r\n" |
| 16589 | "Content-Length: 3\r\n\r\n"), |
| 16590 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16591 | }; |
| 16592 | |
| 16593 | MockRead data_reads[] = { |
| 16594 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16595 | MockRead("HTTP/1.0 400 Not OK\r\n\r\n"), |
| 16596 | MockRead("hello world"), |
| 16597 | MockRead(SYNCHRONOUS, OK), |
| 16598 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16599 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16600 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16601 | |
| 16602 | TestCompletionCallback callback; |
| 16603 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16604 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16605 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16606 | |
| 16607 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16608 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16609 | |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16610 | const HttpResponseInfo* response = trans.GetResponseInfo(); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16611 | ASSERT_TRUE(response); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16612 | |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16613 | EXPECT_TRUE(response->headers); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16614 | EXPECT_EQ("HTTP/1.0 400 Not OK", response->headers->GetStatusLine()); |
| 16615 | |
| 16616 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16617 | rv = ReadTransaction(&trans, &response_data); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16618 | EXPECT_THAT(rv, IsOk()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16619 | EXPECT_EQ("hello world", response_data); |
| 16620 | } |
| 16621 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16622 | TEST_F(HttpNetworkTransactionTest, PostIgnoresNonErrorResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16623 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16624 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16625 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16626 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16627 | |
| 16628 | HttpRequestInfo request; |
| 16629 | request.method = "POST"; |
| 16630 | request.url = GURL("http://www.foo.com/"); |
| 16631 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16632 | request.traffic_annotation = |
| 16633 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16634 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16635 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16636 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16637 | // Send headers successfully, but get an error while sending the body. |
| 16638 | MockWrite data_writes[] = { |
| 16639 | MockWrite("POST / HTTP/1.1\r\n" |
| 16640 | "Host: www.foo.com\r\n" |
| 16641 | "Connection: keep-alive\r\n" |
| 16642 | "Content-Length: 3\r\n\r\n"), |
| 16643 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16644 | }; |
| 16645 | |
| 16646 | MockRead data_reads[] = { |
| 16647 | MockRead("HTTP/1.0 200 Just Dandy\r\n\r\n"), |
| 16648 | MockRead("hello world"), |
| 16649 | MockRead(SYNCHRONOUS, OK), |
| 16650 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16651 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16652 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16653 | |
| 16654 | TestCompletionCallback callback; |
| 16655 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16656 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16657 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16658 | |
| 16659 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16660 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16661 | } |
| 16662 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16663 | TEST_F(HttpNetworkTransactionTest, |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16664 | PostIgnoresNonErrorResponseAfterResetAnd100) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16665 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16666 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16667 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16668 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16669 | |
| 16670 | HttpRequestInfo request; |
| 16671 | request.method = "POST"; |
| 16672 | request.url = GURL("http://www.foo.com/"); |
| 16673 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16674 | request.traffic_annotation = |
| 16675 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16676 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16677 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16678 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16679 | // Send headers successfully, but get an error while sending the body. |
| 16680 | MockWrite data_writes[] = { |
| 16681 | MockWrite("POST / HTTP/1.1\r\n" |
| 16682 | "Host: www.foo.com\r\n" |
| 16683 | "Connection: keep-alive\r\n" |
| 16684 | "Content-Length: 3\r\n\r\n"), |
| 16685 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16686 | }; |
| 16687 | |
| 16688 | MockRead data_reads[] = { |
| 16689 | MockRead("HTTP/1.0 100 Continue\r\n\r\n"), |
| 16690 | MockRead("HTTP/1.0 302 Redirect\r\n"), |
| 16691 | MockRead("Location: http://somewhere-else.com/\r\n"), |
| 16692 | MockRead("Content-Length: 0\r\n\r\n"), |
| 16693 | MockRead(SYNCHRONOUS, OK), |
| 16694 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16695 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 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] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16702 | |
| 16703 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16704 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16705 | } |
| 16706 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16707 | TEST_F(HttpNetworkTransactionTest, PostIgnoresHttp09ResponseAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16708 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16709 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16710 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16711 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16712 | |
| 16713 | HttpRequestInfo request; |
| 16714 | request.method = "POST"; |
| 16715 | request.url = GURL("http://www.foo.com/"); |
| 16716 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16717 | request.traffic_annotation = |
| 16718 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16719 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16720 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16721 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16722 | // Send headers successfully, but get an error while sending the body. |
| 16723 | MockWrite data_writes[] = { |
| 16724 | MockWrite("POST / HTTP/1.1\r\n" |
| 16725 | "Host: www.foo.com\r\n" |
| 16726 | "Connection: keep-alive\r\n" |
| 16727 | "Content-Length: 3\r\n\r\n"), |
| 16728 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16729 | }; |
| 16730 | |
| 16731 | MockRead data_reads[] = { |
| 16732 | MockRead("HTTP 0.9 rocks!"), |
| 16733 | MockRead(SYNCHRONOUS, OK), |
| 16734 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16735 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16736 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16737 | |
| 16738 | TestCompletionCallback callback; |
| 16739 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16740 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16741 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16742 | |
| 16743 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16744 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16745 | } |
| 16746 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16747 | TEST_F(HttpNetworkTransactionTest, PostIgnoresPartial400HeadersAfterReset) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16748 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16749 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16750 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 16751 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16752 | |
| 16753 | HttpRequestInfo request; |
| 16754 | request.method = "POST"; |
| 16755 | request.url = GURL("http://www.foo.com/"); |
| 16756 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16757 | request.traffic_annotation = |
| 16758 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16759 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16760 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 16761 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16762 | // Send headers successfully, but get an error while sending the body. |
| 16763 | MockWrite data_writes[] = { |
| 16764 | MockWrite("POST / HTTP/1.1\r\n" |
| 16765 | "Host: www.foo.com\r\n" |
| 16766 | "Connection: keep-alive\r\n" |
| 16767 | "Content-Length: 3\r\n\r\n"), |
| 16768 | MockWrite(SYNCHRONOUS, ERR_CONNECTION_RESET), |
| 16769 | }; |
| 16770 | |
| 16771 | MockRead data_reads[] = { |
| 16772 | MockRead("HTTP/1.0 400 Not a Full Response\r\n"), |
| 16773 | MockRead(SYNCHRONOUS, OK), |
| 16774 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16775 | StaticSocketDataProvider data(data_reads, data_writes); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16776 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16777 | |
| 16778 | TestCompletionCallback callback; |
| 16779 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16780 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16781 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16782 | |
| 16783 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16784 | EXPECT_THAT(rv, IsError(ERR_CONNECTION_RESET)); |
[email protected] | 02d74a0 | 2014-04-23 18:10:54 | [diff] [blame] | 16785 | } |
| 16786 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16787 | #if BUILDFLAG(ENABLE_WEBSOCKETS) |
| 16788 | |
| 16789 | namespace { |
| 16790 | |
| 16791 | void AddWebSocketHeaders(HttpRequestHeaders* headers) { |
| 16792 | headers->SetHeader("Connection", "Upgrade"); |
| 16793 | headers->SetHeader("Upgrade", "websocket"); |
| 16794 | headers->SetHeader("Origin", "http://www.example.org"); |
| 16795 | headers->SetHeader("Sec-WebSocket-Version", "13"); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16796 | } |
| 16797 | |
| 16798 | } // namespace |
| 16799 | |
| 16800 | TEST_F(HttpNetworkTransactionTest, CreateWebSocketHandshakeStream) { |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 16801 | for (bool secure : {true, false}) { |
| 16802 | MockWrite data_writes[] = { |
| 16803 | MockWrite("GET / HTTP/1.1\r\n" |
| 16804 | "Host: www.example.org\r\n" |
| 16805 | "Connection: Upgrade\r\n" |
| 16806 | "Upgrade: websocket\r\n" |
| 16807 | "Origin: http://www.example.org\r\n" |
| 16808 | "Sec-WebSocket-Version: 13\r\n" |
| 16809 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 16810 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 16811 | "client_max_window_bits\r\n\r\n")}; |
| 16812 | |
| 16813 | MockRead data_reads[] = { |
| 16814 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 16815 | "Upgrade: websocket\r\n" |
| 16816 | "Connection: Upgrade\r\n" |
| 16817 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
| 16818 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16819 | StaticSocketDataProvider data(data_reads, data_writes); |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 16820 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16821 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16822 | if (secure) |
| 16823 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16824 | |
| 16825 | HttpRequestInfo request; |
| 16826 | request.method = "GET"; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 16827 | request.url = |
| 16828 | GURL(secure ? "ws://www.example.org/" : "wss://www.example.org/"); |
| 16829 | AddWebSocketHeaders(&request.extra_headers); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16830 | request.traffic_annotation = |
| 16831 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16832 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 16833 | TestWebSocketHandshakeStreamCreateHelper |
| 16834 | websocket_handshake_stream_create_helper; |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16835 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 16836 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16837 | HttpNetworkTransaction trans(LOW, session.get()); |
| 16838 | trans.SetWebSocketHandshakeStreamCreateHelper( |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 16839 | &websocket_handshake_stream_create_helper); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16840 | |
| 16841 | TestCompletionCallback callback; |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 16842 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 16843 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16844 | |
Bence Béky | 2fcf4fa | 2018-04-06 20:06:01 | [diff] [blame] | 16845 | const HttpStreamRequest* stream_request = trans.stream_request_.get(); |
| 16846 | ASSERT_TRUE(stream_request); |
| 16847 | EXPECT_EQ(&websocket_handshake_stream_create_helper, |
| 16848 | stream_request->websocket_handshake_stream_create_helper()); |
| 16849 | |
| 16850 | rv = callback.WaitForResult(); |
| 16851 | EXPECT_THAT(rv, IsOk()); |
| 16852 | |
| 16853 | EXPECT_TRUE(data.AllReadDataConsumed()); |
| 16854 | EXPECT_TRUE(data.AllWriteDataConsumed()); |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 16855 | } |
| 16856 | } |
| 16857 | |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16858 | // Verify that proxy headers are not sent to the destination server when |
| 16859 | // establishing a tunnel for a secure WebSocket connection. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16860 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWssTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16861 | HttpRequestInfo request; |
| 16862 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16863 | request.url = GURL("wss://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16864 | request.traffic_annotation = |
| 16865 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16866 | AddWebSocketHeaders(&request.extra_headers); |
| 16867 | |
| 16868 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16869 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16870 | ProxyResolutionService::CreateFixedFromPacResult( |
| 16871 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16872 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16873 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16874 | |
| 16875 | // Since a proxy is configured, try to establish a tunnel. |
| 16876 | MockWrite data_writes[] = { |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16877 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16878 | "Host: www.example.org:443\r\n" |
| 16879 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16880 | |
| 16881 | // After calling trans->RestartWithAuth(), this is the request we should |
| 16882 | // be issuing -- the final header line contains the credentials. |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16883 | MockWrite("CONNECT www.example.org:443 HTTP/1.1\r\n" |
| 16884 | "Host: www.example.org:443\r\n" |
| 16885 | "Proxy-Connection: keep-alive\r\n" |
| 16886 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16887 | |
rsleevi | db16bb0 | 2015-11-12 23:47:17 | [diff] [blame] | 16888 | MockWrite("GET / HTTP/1.1\r\n" |
| 16889 | "Host: www.example.org\r\n" |
| 16890 | "Connection: Upgrade\r\n" |
| 16891 | "Upgrade: websocket\r\n" |
| 16892 | "Origin: http://www.example.org\r\n" |
| 16893 | "Sec-WebSocket-Version: 13\r\n" |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16894 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 16895 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 16896 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16897 | |
| 16898 | // The proxy responds to the connect with a 407, using a persistent |
| 16899 | // connection. |
| 16900 | MockRead data_reads[] = { |
| 16901 | // No credentials. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16902 | MockRead("HTTP/1.1 407 Proxy Authentication Required\r\n" |
| 16903 | "Proxy-Authenticate: Basic realm=\"MyRealm1\"\r\n" |
| 16904 | "Content-Length: 0\r\n" |
| 16905 | "Proxy-Connection: keep-alive\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16906 | |
| 16907 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 16908 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16909 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 16910 | "Upgrade: websocket\r\n" |
| 16911 | "Connection: Upgrade\r\n" |
| 16912 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16913 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 16914 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16915 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 16916 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 16917 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 16918 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16919 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 16920 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 16921 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 16922 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16923 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 16924 | &websocket_stream_create_helper); |
| 16925 | |
| 16926 | { |
| 16927 | TestCompletionCallback callback; |
| 16928 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 16929 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16930 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16931 | |
| 16932 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16933 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16934 | } |
| 16935 | |
| 16936 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 16937 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16938 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16939 | EXPECT_EQ(407, response->headers->response_code()); |
| 16940 | |
| 16941 | { |
| 16942 | TestCompletionCallback callback; |
| 16943 | |
| 16944 | int rv = trans->RestartWithAuth(AuthCredentials(kFoo, kBar), |
| 16945 | callback.callback()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16946 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16947 | |
| 16948 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 16949 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16950 | } |
| 16951 | |
| 16952 | response = trans->GetResponseInfo(); |
| 16953 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 16954 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16955 | |
| 16956 | EXPECT_EQ(101, response->headers->response_code()); |
| 16957 | |
| 16958 | trans.reset(); |
| 16959 | session->CloseAllConnections(); |
| 16960 | } |
| 16961 | |
| 16962 | // Verify that proxy headers are not sent to the destination server when |
| 16963 | // establishing a tunnel for an insecure WebSocket connection. |
| 16964 | // This requires the authentication info to be injected into the auth cache |
| 16965 | // due to crbug.com/395064 |
| 16966 | // TODO(ricea): Change to use a 407 response once issue 395064 is fixed. |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 16967 | TEST_F(HttpNetworkTransactionTest, ProxyHeadersNotSentOverWsTunnel) { |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16968 | HttpRequestInfo request; |
| 16969 | request.method = "GET"; |
bnc | ce36dca2 | 2015-04-21 22:11:23 | [diff] [blame] | 16970 | request.url = GURL("ws://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 16971 | request.traffic_annotation = |
| 16972 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16973 | AddWebSocketHeaders(&request.extra_headers); |
| 16974 | |
| 16975 | // Configure against proxy server "myproxy:70". |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 16976 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 16977 | ProxyResolutionService::CreateFixedFromPacResult( |
| 16978 | "PROXY myproxy:70", TRAFFIC_ANNOTATION_FOR_TESTS); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16979 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 16980 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16981 | |
| 16982 | MockWrite data_writes[] = { |
| 16983 | // Try to establish a tunnel for the WebSocket connection, with |
| 16984 | // credentials. Because WebSockets have a separate set of socket pools, |
| 16985 | // they cannot and will not use the same TCP/IP connection as the |
| 16986 | // preflight HTTP request. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16987 | MockWrite("CONNECT www.example.org:80 HTTP/1.1\r\n" |
| 16988 | "Host: www.example.org:80\r\n" |
| 16989 | "Proxy-Connection: keep-alive\r\n" |
| 16990 | "Proxy-Authorization: Basic Zm9vOmJhcg==\r\n\r\n"), |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 16991 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 16992 | MockWrite("GET / HTTP/1.1\r\n" |
| 16993 | "Host: www.example.org\r\n" |
| 16994 | "Connection: Upgrade\r\n" |
| 16995 | "Upgrade: websocket\r\n" |
| 16996 | "Origin: http://www.example.org\r\n" |
| 16997 | "Sec-WebSocket-Version: 13\r\n" |
| 16998 | "Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==\r\n" |
| 16999 | "Sec-WebSocket-Extensions: permessage-deflate; " |
| 17000 | "client_max_window_bits\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17001 | |
| 17002 | MockRead data_reads[] = { |
| 17003 | // HTTP CONNECT with credentials. |
| 17004 | MockRead("HTTP/1.1 200 Connection Established\r\n\r\n"), |
| 17005 | |
| 17006 | // WebSocket connection established inside tunnel. |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17007 | MockRead("HTTP/1.1 101 Switching Protocols\r\n" |
| 17008 | "Upgrade: websocket\r\n" |
| 17009 | "Connection: Upgrade\r\n" |
| 17010 | "Sec-WebSocket-Accept: s3pPLMBiTxaQ9kYGzzhZRbK+xOo=\r\n\r\n")}; |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17011 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17012 | StaticSocketDataProvider data(data_reads, data_writes); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17013 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17014 | |
| 17015 | session->http_auth_cache()->Add( |
| 17016 | GURL("http://myproxy:70/"), "MyRealm1", HttpAuth::AUTH_SCHEME_BASIC, |
| 17017 | "Basic realm=MyRealm1", AuthCredentials(kFoo, kBar), "/"); |
| 17018 | |
Bence Béky | 8d1c605 | 2018-02-07 12:48:15 | [diff] [blame] | 17019 | TestWebSocketHandshakeStreamCreateHelper websocket_stream_create_helper; |
| 17020 | |
bnc | 87dcefc | 2017-05-25 12:47:58 | [diff] [blame] | 17021 | auto trans = |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17022 | std::make_unique<HttpNetworkTransaction>(DEFAULT_PRIORITY, session.get()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17023 | trans->SetWebSocketHandshakeStreamCreateHelper( |
| 17024 | &websocket_stream_create_helper); |
| 17025 | |
| 17026 | TestCompletionCallback callback; |
| 17027 | |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17028 | int rv = trans->Start(&request, callback.callback(), NetLogWithSource()); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17029 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17030 | |
| 17031 | rv = callback.WaitForResult(); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17032 | EXPECT_THAT(rv, IsOk()); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17033 | |
| 17034 | const HttpResponseInfo* response = trans->GetResponseInfo(); |
| 17035 | ASSERT_TRUE(response); |
wez | ca107093 | 2016-05-26 20:30:52 | [diff] [blame] | 17036 | ASSERT_TRUE(response->headers); |
Adam Rice | 425cf12 | 2015-01-19 06:18:24 | [diff] [blame] | 17037 | |
| 17038 | EXPECT_EQ(101, response->headers->response_code()); |
| 17039 | |
| 17040 | trans.reset(); |
| 17041 | session->CloseAllConnections(); |
| 17042 | } |
| 17043 | |
Bence Béky | dca6bd9 | 2018-01-30 13:43:06 | [diff] [blame] | 17044 | #endif // BUILDFLAG(ENABLE_WEBSOCKETS) |
| 17045 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17046 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17047 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17048 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17049 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17050 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17051 | |
| 17052 | HttpRequestInfo request; |
| 17053 | request.method = "POST"; |
| 17054 | request.url = GURL("http://www.foo.com/"); |
| 17055 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17056 | request.traffic_annotation = |
| 17057 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17058 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17059 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17060 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17061 | MockWrite data_writes[] = { |
| 17062 | MockWrite("POST / HTTP/1.1\r\n" |
| 17063 | "Host: www.foo.com\r\n" |
| 17064 | "Connection: keep-alive\r\n" |
| 17065 | "Content-Length: 3\r\n\r\n"), |
| 17066 | MockWrite("foo"), |
| 17067 | }; |
| 17068 | |
| 17069 | MockRead data_reads[] = { |
| 17070 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17071 | MockRead(SYNCHRONOUS, OK), |
| 17072 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17073 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17074 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17075 | |
| 17076 | TestCompletionCallback callback; |
| 17077 | |
| 17078 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17079 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17080 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17081 | |
| 17082 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17083 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17084 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17085 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 17086 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17087 | } |
| 17088 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17089 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesPost100Continue) { |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17090 | std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17091 | element_readers.push_back( |
Jeremy Roman | 0579ed6 | 2017-08-29 15:56:19 | [diff] [blame] | 17092 | std::make_unique<UploadBytesElementReader>("foo", 3)); |
olli.raula | 6df48b2a | 2015-11-26 07:40:22 | [diff] [blame] | 17093 | ElementsUploadDataStream upload_data_stream(std::move(element_readers), 0); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17094 | |
| 17095 | HttpRequestInfo request; |
| 17096 | request.method = "POST"; |
| 17097 | request.url = GURL("http://www.foo.com/"); |
| 17098 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17099 | request.traffic_annotation = |
| 17100 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17101 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17102 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17103 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17104 | MockWrite data_writes[] = { |
| 17105 | MockWrite("POST / HTTP/1.1\r\n" |
| 17106 | "Host: www.foo.com\r\n" |
| 17107 | "Connection: keep-alive\r\n" |
| 17108 | "Content-Length: 3\r\n\r\n"), |
| 17109 | MockWrite("foo"), |
| 17110 | }; |
| 17111 | |
| 17112 | MockRead data_reads[] = { |
| 17113 | MockRead("HTTP/1.1 100 Continue\r\n\r\n"), |
| 17114 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17115 | MockRead(SYNCHRONOUS, OK), |
| 17116 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17117 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17118 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17119 | |
| 17120 | TestCompletionCallback callback; |
| 17121 | |
| 17122 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17123 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17124 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17125 | |
| 17126 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17127 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17128 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17129 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 17130 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17131 | } |
| 17132 | |
bnc | d16676a | 2016-07-20 16:23:01 | [diff] [blame] | 17133 | TEST_F(HttpNetworkTransactionTest, TotalNetworkBytesChunkedPost) { |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17134 | ChunkedUploadDataStream upload_data_stream(0); |
| 17135 | |
| 17136 | HttpRequestInfo request; |
| 17137 | request.method = "POST"; |
| 17138 | request.url = GURL("http://www.foo.com/"); |
| 17139 | request.upload_data_stream = &upload_data_stream; |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17140 | request.traffic_annotation = |
| 17141 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17142 | |
danakj | 1fd259a0 | 2016-04-16 03:17:09 | [diff] [blame] | 17143 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17144 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17145 | // Send headers successfully, but get an error while sending the body. |
| 17146 | MockWrite data_writes[] = { |
| 17147 | MockWrite("POST / HTTP/1.1\r\n" |
| 17148 | "Host: www.foo.com\r\n" |
| 17149 | "Connection: keep-alive\r\n" |
| 17150 | "Transfer-Encoding: chunked\r\n\r\n"), |
| 17151 | MockWrite("1\r\nf\r\n"), MockWrite("2\r\noo\r\n"), MockWrite("0\r\n\r\n"), |
| 17152 | }; |
| 17153 | |
| 17154 | MockRead data_reads[] = { |
| 17155 | MockRead("HTTP/1.1 200 OK\r\n\r\n"), MockRead("hello world"), |
| 17156 | MockRead(SYNCHRONOUS, OK), |
| 17157 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17158 | StaticSocketDataProvider data(data_reads, data_writes); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17159 | session_deps_.socket_factory->AddSocketDataProvider(&data); |
| 17160 | |
| 17161 | TestCompletionCallback callback; |
| 17162 | |
| 17163 | EXPECT_EQ(ERR_IO_PENDING, |
tfarina | 4283411 | 2016-09-22 13:38:20 | [diff] [blame] | 17164 | trans.Start(&request, callback.callback(), NetLogWithSource())); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17165 | |
| 17166 | base::RunLoop().RunUntilIdle(); |
| 17167 | upload_data_stream.AppendData("f", 1, false); |
| 17168 | |
| 17169 | base::RunLoop().RunUntilIdle(); |
| 17170 | upload_data_stream.AppendData("oo", 2, true); |
| 17171 | |
robpercival | 214763f | 2016-07-01 23:27:01 | [diff] [blame] | 17172 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17173 | |
| 17174 | std::string response_data; |
bnc | 691fda6 | 2016-08-12 00:43:16 | [diff] [blame] | 17175 | EXPECT_THAT(ReadTransaction(&trans, &response_data), IsOk()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17176 | |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17177 | EXPECT_EQ(CountWriteBytes(data_writes), trans.GetTotalSentBytes()); |
| 17178 | EXPECT_EQ(CountReadBytes(data_reads), trans.GetTotalReceivedBytes()); |
sclittle | fb24989 | 2015-09-10 21:33:22 | [diff] [blame] | 17179 | } |
| 17180 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17181 | void CheckContentEncodingMatching(SpdySessionDependencies* session_deps, |
| 17182 | const std::string& accept_encoding, |
| 17183 | const std::string& content_encoding, |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17184 | const std::string& location, |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17185 | bool should_match) { |
| 17186 | HttpRequestInfo request; |
| 17187 | request.method = "GET"; |
| 17188 | request.url = GURL("http://www.foo.com/"); |
| 17189 | request.extra_headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, |
| 17190 | accept_encoding); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17191 | request.traffic_annotation = |
| 17192 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17193 | |
| 17194 | std::unique_ptr<HttpNetworkSession> session(CreateSession(session_deps)); |
| 17195 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17196 | // Send headers successfully, but get an error while sending the body. |
| 17197 | MockWrite data_writes[] = { |
| 17198 | MockWrite("GET / HTTP/1.1\r\n" |
| 17199 | "Host: www.foo.com\r\n" |
| 17200 | "Connection: keep-alive\r\n" |
| 17201 | "Accept-Encoding: "), |
| 17202 | MockWrite(accept_encoding.data()), MockWrite("\r\n\r\n"), |
| 17203 | }; |
| 17204 | |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17205 | std::string response_code = "200 OK"; |
| 17206 | std::string extra; |
| 17207 | if (!location.empty()) { |
| 17208 | response_code = "301 Redirect\r\nLocation: "; |
| 17209 | response_code.append(location); |
| 17210 | } |
| 17211 | |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17212 | MockRead data_reads[] = { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17213 | MockRead("HTTP/1.0 "), |
| 17214 | MockRead(response_code.data()), |
| 17215 | MockRead("\r\nContent-Encoding: "), |
| 17216 | MockRead(content_encoding.data()), |
| 17217 | MockRead("\r\n\r\n"), |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17218 | MockRead(SYNCHRONOUS, OK), |
| 17219 | }; |
Ryan Sleevi | b8d7ea0 | 2018-05-07 20:01:01 | [diff] [blame] | 17220 | StaticSocketDataProvider data(data_reads, data_writes); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17221 | session_deps->socket_factory->AddSocketDataProvider(&data); |
| 17222 | |
| 17223 | TestCompletionCallback callback; |
| 17224 | |
| 17225 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17226 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17227 | |
| 17228 | rv = callback.WaitForResult(); |
| 17229 | if (should_match) { |
| 17230 | EXPECT_THAT(rv, IsOk()); |
| 17231 | } else { |
| 17232 | EXPECT_THAT(rv, IsError(ERR_CONTENT_DECODING_FAILED)); |
| 17233 | } |
| 17234 | } |
| 17235 | |
| 17236 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding1) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17237 | CheckContentEncodingMatching(&session_deps_, "gzip,sdch", "br", "", false); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17238 | } |
| 17239 | |
| 17240 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding2) { |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17241 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "", "", |
| 17242 | true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17243 | } |
| 17244 | |
| 17245 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding3) { |
| 17246 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
sky | 50576f3 | 2017-05-01 19:28:03 | [diff] [blame] | 17247 | "", false); |
| 17248 | } |
| 17249 | |
| 17250 | TEST_F(HttpNetworkTransactionTest, MatchContentEncoding4) { |
| 17251 | CheckContentEncodingMatching(&session_deps_, "identity;q=1, *;q=0", "gzip", |
| 17252 | "www.foo.com/other", true); |
eustas | c7d27da | 2017-04-06 10:33:20 | [diff] [blame] | 17253 | } |
| 17254 | |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17255 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsSync) { |
| 17256 | ProxyConfig proxy_config; |
| 17257 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17258 | proxy_config.set_pac_mandatory(true); |
| 17259 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17260 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17261 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 17262 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Bence Béky | 8f9d7d395 | 2017-10-09 19:58:04 | [diff] [blame] | 17263 | std::make_unique<FailingProxyResolverFactory>(), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17264 | |
| 17265 | HttpRequestInfo request; |
| 17266 | request.method = "GET"; |
| 17267 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17268 | request.traffic_annotation = |
| 17269 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17270 | |
| 17271 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17272 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17273 | |
| 17274 | TestCompletionCallback callback; |
| 17275 | |
| 17276 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17277 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17278 | EXPECT_THAT(callback.WaitForResult(), |
| 17279 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17280 | } |
| 17281 | |
| 17282 | TEST_F(HttpNetworkTransactionTest, ProxyResolutionFailsAsync) { |
| 17283 | ProxyConfig proxy_config; |
| 17284 | proxy_config.set_pac_url(GURL("http://fooproxyurl")); |
| 17285 | proxy_config.set_pac_mandatory(true); |
| 17286 | MockAsyncProxyResolverFactory* proxy_resolver_factory = |
| 17287 | new MockAsyncProxyResolverFactory(false); |
| 17288 | MockAsyncProxyResolver resolver; |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17289 | session_deps_.proxy_resolution_service.reset(new ProxyResolutionService( |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17290 | std::make_unique<ProxyConfigServiceFixed>(ProxyConfigWithAnnotation( |
| 17291 | proxy_config, TRAFFIC_ANNOTATION_FOR_TESTS)), |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17292 | base::WrapUnique(proxy_resolver_factory), nullptr)); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17293 | HttpRequestInfo request; |
| 17294 | request.method = "GET"; |
| 17295 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17296 | request.traffic_annotation = |
| 17297 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17298 | |
| 17299 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17300 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17301 | |
| 17302 | TestCompletionCallback callback; |
| 17303 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17304 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17305 | |
| 17306 | proxy_resolver_factory->pending_requests()[0]->CompleteNowWithForwarder( |
| 17307 | ERR_FAILED, &resolver); |
| 17308 | EXPECT_THAT(callback.WaitForResult(), |
| 17309 | IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
| 17310 | } |
| 17311 | |
| 17312 | TEST_F(HttpNetworkTransactionTest, NoSupportedProxies) { |
Lily Houghton | 8c2f97d | 2018-01-22 05:06:59 | [diff] [blame] | 17313 | session_deps_.proxy_resolution_service = |
Ramin Halavati | ca8d525 | 2018-03-12 05:33:49 | [diff] [blame] | 17314 | ProxyResolutionService::CreateFixedFromPacResult( |
| 17315 | "QUIC myproxy.org:443", TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17316 | session_deps_.enable_quic = false; |
| 17317 | std::unique_ptr<HttpNetworkSession> session(CreateSession(&session_deps_)); |
| 17318 | |
| 17319 | HttpRequestInfo request; |
| 17320 | request.method = "GET"; |
| 17321 | request.url = GURL("http://www.example.org/"); |
Ramin Halavati | b5e433e | 2018-02-07 07:41:10 | [diff] [blame] | 17322 | request.traffic_annotation = |
| 17323 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
xunjieli | 96f2a40 | 2017-06-05 17:24:27 | [diff] [blame] | 17324 | |
| 17325 | TestCompletionCallback callback; |
| 17326 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17327 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17328 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17329 | |
| 17330 | EXPECT_THAT(callback.WaitForResult(), IsError(ERR_NO_SUPPORTED_PROXIES)); |
| 17331 | } |
| 17332 | |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 17333 | //----------------------------------------------------------------------------- |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 17334 | // Reporting tests |
| 17335 | |
| 17336 | #if BUILDFLAG(ENABLE_REPORTING) |
| 17337 | class HttpNetworkTransactionReportingTest : public HttpNetworkTransactionTest { |
| 17338 | protected: |
| 17339 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 17340 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 134b52e | 2018-11-09 18:00:14 | [diff] [blame] | 17341 | auto test_reporting_context = std::make_unique<TestReportingContext>( |
| 17342 | &clock_, &tick_clock_, ReportingPolicy()); |
| 17343 | test_reporting_context_ = test_reporting_context.get(); |
| 17344 | session_deps_.reporting_service = |
| 17345 | ReportingService::CreateForTesting(std::move(test_reporting_context)); |
| 17346 | } |
| 17347 | |
| 17348 | TestReportingContext* reporting_context() const { |
| 17349 | return test_reporting_context_; |
| 17350 | } |
| 17351 | |
| 17352 | void clear_reporting_service() { |
| 17353 | session_deps_.reporting_service.reset(); |
| 17354 | test_reporting_context_ = nullptr; |
| 17355 | } |
| 17356 | |
| 17357 | // Makes an HTTPS request that should install a valid Reporting policy. |
| 17358 | void RequestPolicy() { |
| 17359 | MockRead data_reads[] = { |
| 17360 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 17361 | MockRead("Report-To: {\"group\": \"nel\", \"max_age\": 86400, " |
| 17362 | "\"endpoints\": [{\"url\": " |
| 17363 | "\"https://www.example.org/upload/\"}]}\r\n"), |
| 17364 | MockRead("\r\n"), |
| 17365 | MockRead("hello world"), |
| 17366 | MockRead(SYNCHRONOUS, OK), |
| 17367 | }; |
| 17368 | MockWrite data_writes[] = { |
| 17369 | MockWrite("GET / HTTP/1.1\r\n" |
| 17370 | "Host: www.example.org\r\n" |
| 17371 | "Connection: keep-alive\r\n\r\n"), |
| 17372 | }; |
| 17373 | |
| 17374 | HttpRequestInfo request; |
| 17375 | request.method = "GET"; |
| 17376 | request.url = GURL(url_); |
| 17377 | request.traffic_annotation = |
| 17378 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 17379 | |
| 17380 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17381 | if (request.url.SchemeIsCryptographic()) { |
| 17382 | ssl.ssl_info.cert = |
| 17383 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 17384 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 17385 | ssl.ssl_info.cert_status = cert_status_; |
| 17386 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17387 | } |
| 17388 | |
| 17389 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 17390 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17391 | |
| 17392 | TestCompletionCallback callback; |
| 17393 | auto session = CreateSession(&session_deps_); |
| 17394 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17395 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17396 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17397 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 17398 | } |
| 17399 | |
| 17400 | protected: |
| 17401 | std::string url_ = "https://www.example.org/"; |
| 17402 | CertStatus cert_status_ = 0; |
| 17403 | |
| 17404 | private: |
| 17405 | TestReportingContext* test_reporting_context_; |
| 17406 | }; |
| 17407 | |
| 17408 | TEST_F(HttpNetworkTransactionReportingTest, |
| 17409 | DontProcessReportToHeaderNoService) { |
| 17410 | base::HistogramTester histograms; |
| 17411 | clear_reporting_service(); |
| 17412 | RequestPolicy(); |
| 17413 | histograms.ExpectBucketCount( |
| 17414 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 17415 | ReportingHeaderParser::HeaderOutcome::DISCARDED_NO_REPORTING_SERVICE, 1); |
| 17416 | } |
| 17417 | |
| 17418 | TEST_F(HttpNetworkTransactionReportingTest, DontProcessReportToHeaderHttp) { |
| 17419 | base::HistogramTester histograms; |
| 17420 | url_ = "http://www.example.org/"; |
| 17421 | RequestPolicy(); |
| 17422 | histograms.ExpectBucketCount( |
| 17423 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 17424 | ReportingHeaderParser::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 17425 | } |
| 17426 | |
| 17427 | TEST_F(HttpNetworkTransactionReportingTest, ProcessReportToHeaderHttps) { |
| 17428 | RequestPolicy(); |
| 17429 | std::vector<const ReportingClient*> clients; |
| 17430 | reporting_context()->cache()->GetClients(&clients); |
| 17431 | ASSERT_EQ(1u, clients.size()); |
| 17432 | const auto* client = clients[0]; |
| 17433 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 17434 | client->origin); |
| 17435 | EXPECT_EQ(GURL("https://www.example.org/upload/"), client->endpoint); |
| 17436 | EXPECT_EQ("nel", client->group); |
| 17437 | } |
| 17438 | |
| 17439 | TEST_F(HttpNetworkTransactionReportingTest, |
| 17440 | DontProcessReportToHeaderInvalidHttps) { |
| 17441 | base::HistogramTester histograms; |
| 17442 | cert_status_ = CERT_STATUS_COMMON_NAME_INVALID; |
| 17443 | RequestPolicy(); |
| 17444 | histograms.ExpectBucketCount( |
| 17445 | ReportingHeaderParser::kHeaderOutcomeHistogram, |
| 17446 | ReportingHeaderParser::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, 1); |
| 17447 | } |
| 17448 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 17449 | |
| 17450 | //----------------------------------------------------------------------------- |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 17451 | // Network Error Logging tests |
| 17452 | |
| 17453 | #if BUILDFLAG(ENABLE_REPORTING) |
| 17454 | class HttpNetworkTransactionNetworkErrorLoggingTest |
| 17455 | : public HttpNetworkTransactionTest { |
| 17456 | protected: |
| 17457 | void SetUp() override { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 17458 | HttpNetworkTransactionTest::SetUp(); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 17459 | auto network_error_logging_service = |
| 17460 | std::make_unique<TestNetworkErrorLoggingService>(); |
| 17461 | test_network_error_logging_service_ = network_error_logging_service.get(); |
| 17462 | session_deps_.network_error_logging_service = |
| 17463 | std::move(network_error_logging_service); |
| 17464 | } |
| 17465 | |
| 17466 | TestNetworkErrorLoggingService* network_error_logging_service() const { |
| 17467 | return test_network_error_logging_service_; |
| 17468 | } |
| 17469 | |
| 17470 | void clear_network_error_logging_service() { |
| 17471 | session_deps_.network_error_logging_service.reset(); |
| 17472 | test_network_error_logging_service_ = nullptr; |
| 17473 | } |
| 17474 | |
| 17475 | // Makes an HTTPS request that should install a valid NEL policy. |
| 17476 | void RequestPolicy() { |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 17477 | std::string extra_header_string = extra_headers_.ToString(); |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 17478 | MockRead data_reads[] = { |
| 17479 | MockRead("HTTP/1.0 200 OK\r\n"), |
| 17480 | MockRead("NEL: {\"report_to\": \"nel\", \"max_age\": 86400}\r\n"), |
| 17481 | MockRead("\r\n"), |
| 17482 | MockRead("hello world"), |
| 17483 | MockRead(SYNCHRONOUS, OK), |
| 17484 | }; |
| 17485 | MockWrite data_writes[] = { |
| 17486 | MockWrite("GET / HTTP/1.1\r\n" |
| 17487 | "Host: www.example.org\r\n" |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 17488 | "Connection: keep-alive\r\n"), |
| 17489 | MockWrite(ASYNC, extra_header_string.data(), |
| 17490 | extra_header_string.size()), |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 17491 | }; |
| 17492 | |
| 17493 | HttpRequestInfo request; |
| 17494 | request.method = "GET"; |
| 17495 | request.url = GURL(url_); |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 17496 | request.extra_headers = extra_headers_; |
| 17497 | request.reporting_upload_depth = reporting_upload_depth_; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 17498 | request.traffic_annotation = |
| 17499 | net::MutableNetworkTrafficAnnotationTag(TRAFFIC_ANNOTATION_FOR_TESTS); |
| 17500 | |
| 17501 | SSLSocketDataProvider ssl(ASYNC, OK); |
| 17502 | if (request.url.SchemeIsCryptographic()) { |
| 17503 | ssl.ssl_info.cert = |
| 17504 | ImportCertFromFile(GetTestCertsDirectory(), "wildcard.pem"); |
| 17505 | ASSERT_TRUE(ssl.ssl_info.cert); |
| 17506 | ssl.ssl_info.cert_status = cert_status_; |
| 17507 | session_deps_.socket_factory->AddSSLSocketDataProvider(&ssl); |
| 17508 | } |
| 17509 | |
| 17510 | StaticSocketDataProvider reads(data_reads, data_writes); |
| 17511 | session_deps_.socket_factory->AddSocketDataProvider(&reads); |
| 17512 | |
| 17513 | TestCompletionCallback callback; |
| 17514 | auto session = CreateSession(&session_deps_); |
| 17515 | HttpNetworkTransaction trans(DEFAULT_PRIORITY, session.get()); |
| 17516 | int rv = trans.Start(&request, callback.callback(), NetLogWithSource()); |
| 17517 | EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
| 17518 | EXPECT_THAT(callback.WaitForResult(), IsOk()); |
| 17519 | } |
| 17520 | |
| 17521 | protected: |
| 17522 | std::string url_ = "https://www.example.org/"; |
| 17523 | CertStatus cert_status_ = 0; |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 17524 | HttpRequestHeaders extra_headers_; |
| 17525 | int reporting_upload_depth_ = 0; |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 17526 | |
| 17527 | private: |
| 17528 | TestNetworkErrorLoggingService* test_network_error_logging_service_; |
| 17529 | }; |
| 17530 | |
| 17531 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 17532 | DontProcessNelHeaderNoService) { |
| 17533 | base::HistogramTester histograms; |
| 17534 | clear_network_error_logging_service(); |
| 17535 | RequestPolicy(); |
| 17536 | histograms.ExpectBucketCount( |
| 17537 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 17538 | NetworkErrorLoggingService::HeaderOutcome:: |
| 17539 | DISCARDED_NO_NETWORK_ERROR_LOGGING_SERVICE, |
| 17540 | 1); |
| 17541 | } |
| 17542 | |
| 17543 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 17544 | DontProcessNelHeaderHttp) { |
| 17545 | base::HistogramTester histograms; |
| 17546 | url_ = "http://www.example.org/"; |
| 17547 | RequestPolicy(); |
| 17548 | histograms.ExpectBucketCount( |
| 17549 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 17550 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_INVALID_SSL_INFO, 1); |
| 17551 | } |
| 17552 | |
| 17553 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ProcessNelHeaderHttps) { |
| 17554 | RequestPolicy(); |
| 17555 | ASSERT_EQ(1u, network_error_logging_service()->headers().size()); |
| 17556 | const auto& header = network_error_logging_service()->headers()[0]; |
| 17557 | EXPECT_EQ(url::Origin::Create(GURL("https://www.example.org/")), |
| 17558 | header.origin); |
| 17559 | EXPECT_EQ(IPAddress::IPv4Localhost(), header.received_ip_address); |
| 17560 | EXPECT_EQ("{\"report_to\": \"nel\", \"max_age\": 86400}", header.value); |
| 17561 | } |
| 17562 | |
| 17563 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 17564 | DontProcessNelHeaderInvalidHttps) { |
| 17565 | base::HistogramTester histograms; |
| 17566 | cert_status_ = CERT_STATUS_COMMON_NAME_INVALID; |
| 17567 | RequestPolicy(); |
| 17568 | histograms.ExpectBucketCount( |
| 17569 | NetworkErrorLoggingService::kHeaderOutcomeHistogram, |
| 17570 | NetworkErrorLoggingService::HeaderOutcome::DISCARDED_CERT_STATUS_ERROR, |
| 17571 | 1); |
| 17572 | } |
Douglas Creager | ef5eecdc | 2018-11-09 20:50:36 | [diff] [blame] | 17573 | |
| 17574 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, CreateReportHttps) { |
| 17575 | RequestPolicy(); |
| 17576 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 17577 | const auto& error = network_error_logging_service()->errors()[0]; |
| 17578 | EXPECT_EQ(GURL("https://www.example.org/"), error.uri); |
| 17579 | EXPECT_TRUE(error.referrer.is_empty()); |
| 17580 | EXPECT_EQ("", error.user_agent); |
| 17581 | EXPECT_EQ(IPAddress::IPv4Localhost(), error.server_ip); |
| 17582 | EXPECT_EQ("http/1.1", error.protocol); |
| 17583 | EXPECT_EQ("GET", error.method); |
| 17584 | EXPECT_EQ(200, error.status_code); |
| 17585 | EXPECT_EQ(OK, error.type); |
| 17586 | EXPECT_EQ(0, error.reporting_upload_depth); |
| 17587 | } |
| 17588 | |
| 17589 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ReportContainsReferrer) { |
| 17590 | constexpr char kReferrer[] = "https://www.example.org/login/"; |
| 17591 | extra_headers_.SetHeader("Referer", kReferrer); |
| 17592 | RequestPolicy(); |
| 17593 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 17594 | const auto& error = network_error_logging_service()->errors()[0]; |
| 17595 | EXPECT_EQ(GURL(kReferrer), error.referrer); |
| 17596 | } |
| 17597 | |
| 17598 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, |
| 17599 | ReportContainsUploadDepth) { |
| 17600 | reporting_upload_depth_ = 7; |
| 17601 | RequestPolicy(); |
| 17602 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 17603 | const auto& error = network_error_logging_service()->errors()[0]; |
| 17604 | EXPECT_EQ(7, error.reporting_upload_depth); |
| 17605 | } |
| 17606 | |
| 17607 | TEST_F(HttpNetworkTransactionNetworkErrorLoggingTest, ReportContainsUserAgent) { |
| 17608 | constexpr char kUserAgent[] = "Mozilla/1.0"; |
| 17609 | extra_headers_.SetHeader("User-Agent", kUserAgent); |
| 17610 | RequestPolicy(); |
| 17611 | ASSERT_EQ(1u, network_error_logging_service()->errors().size()); |
| 17612 | const auto& error = network_error_logging_service()->errors()[0]; |
| 17613 | EXPECT_EQ(kUserAgent, error.user_agent); |
| 17614 | } |
Douglas Creager | 3cb04205 | 2018-11-06 23:08:52 | [diff] [blame] | 17615 | #endif // BUILDFLAG(ENABLE_REPORTING) |
| 17616 | |
[email protected] | 89ceba9a | 2009-03-21 03:46:06 | [diff] [blame] | 17617 | } // namespace net |